Producer consumer problem
Hi I have a scenario of producer and consumer with bounded buffer (say for example, 3 producers and 2 consumers and capacity to store produced items is 10). Producer consumer can be implemented using mutex and condition variable. This is ok and I am almost clear on this implementation. Now, as it has mutex and mutex is a blocking call, can we have an option to avoid this. Most of the people and articles suggest about the semaphores. I get it that we use two semaphores with signal and wait mechanism. These two semaphores takes care of the empty slots and free slots each. Still queue need to be protected and can be protected using mutex again. So, what is the advantage of semaphores as we still go ahead with blocking calls of mutex again? We excluded condition variables but not mutex by using semaphores. Any thoughts will be of great help. Thanks in advance..!