It is used often when data stream must be arranged between threads or processes, maybe even between a process and a hardware. For example, the bounded bounded buffer data structure is very popular in audio programming. In audio programming, it is usually called "ring buffer". The implementation of such ring buffers is usually different from textbook solutions because at least one party is a real-time thread and should not block (can't wait). Audio programmers usually use "lock-free" solutions based on atomics. For the discussion of specific use cases, check the following cool presentation from CPPCon. The speaker talks about bounded buffer usage. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-boPEO2auJj4.htmlm53s Also, here is a couple of links to the Audacity code. Files RingBuffer.h and RingBuffer.cpp contain the real-life implementation of the bounded buffer. github.com/audacity/audacity/blob/master/src/RingBuffer.h github.com/audacity/audacity/blob/master/src/RingBuffer.cpp
Basically any limited resources which is shared between processes (by processes I mean an abstract process, it could be thread, a file descriptor etc.).
This video was so well made and clearly understandable that I just purchased a subscription. (The price also was right and so it was a no-brainer.) Thank you!
Nice and clear explanation! I am wondering, is it really needed ot have 2 semaphores? You could just use one non-binary semaphore and increment and decrement it accordingly based on which process does which operation.
Thank you. The rest is a part of the online "course" that can be found at binary-wisdom.teachable.com/p/quick-explanations-for-the-operating-systems-course/
More complex synchronization is needed. You got to handle not only producer-consumer synchronization but also make sure that multiple producers or multiple consumers don't conflict between themselves.
You can make it work, though it wouldn't be so elegant. Semaphores are the solution from one of the most popular college textbooks on Operating Systems. If you want to use something like mutexes, you can but don't try to lock the whole buffer with it. It would be very inefficient.
All the necessary synchronization is in place here. You don't need any special mutexes for this version of the problem (single producer and single consumer). Try to come up with a scenario that causes a mistake and you'll see how it works like that.