JOIN ME
—————
YouTube 🎬 [ Ссылка ]
Patreon 🚀 [ Ссылка ]
COMPLETE PLAYLIST
————————————
C++ Tutorial For Beginners: [ Ссылка ]
STL (Standard Template Library): [ Ссылка ]
ThreadIng In C++: [ Ссылка ]
Data Structures: [ Ссылка ]
Algorithms: [ Ссылка ]
Design Patterns: [ Ссылка ]
Smart Pointers: [ Ссылка ]
C++14: [ Ссылка ]
C++17: [ Ссылка ]
C++ All Type Casts: [ Ссылка ]
INTERVIEW PLAYLIST
————————————
C++ Interview Q&A: [ Ссылка ]
C++ Interview Q&A For Experienced: [ Ссылка ]
Linked List Interview Questions: [ Ссылка ]
BST Interview Questions: [ Ссылка ]
Array Interview Questions: [ Ссылка ]
String Interview Questions: [ Ссылка ]
Bit Manipulation Questions: [ Ссылка ]
Binary Tree Interview Question: [ Ссылка ]
Sorting Algorithms: [ Ссылка ]
C++ MCQ: [ Ссылка ]
C MCQ: [ Ссылка ]
C Interview Questions: [ Ссылка ]
QUICK SHORT VIDEOS
————————————-
C++ Short : [ Ссылка ]
C Short : [ Ссылка ]-
Producer Consumer OR Bounded Buffer Problem
THE PROBLEM STATEMENT:
1. Producer will produce and consumer will consume with synchronisation of a common buffer.
2. Until producer thread produces any data consumer thread can't consume.
3. Threads will use condition_variable to notify each other.
4. We need mutex if we use condition_variable because CV waits on mutex.
5. This is one of the example of producer consumer there are many.
PRODUCER thread steps:
1. lock mutex, if success then go ahead otherwise wait for mutex to get free.
2. check if buffer is full and if it is full then unlock mutex and sleep, if not then go ahead and produce.
3. insert item in buffer.
4. unlock mutex.
5. notify consumer.
CONSUMER thread steps:
1. lock mutex, if success then go ahead otherwise wait for mutex to get free.
2. check if buffer is empty and if it is, then unlock the mutex and sleep, if not then go ahead and consume.
3. consume item from buffer.
4. unlock mutex.
5. notify producer.
IMP:
Producer and Consumer have to notify each other upon completion of their job.
#threading #cpp #tutorial #programming #interviewquestions #softwareengineering #computerscience
Ещё видео!