Posts

Showing posts with the label producer consumer

Producer Consumer Problem : Operating System : Semaphores

Image
          A very well known synchronization problem in the study of Operating System is the Producer-Consumer Problem. Any new synchronization technique should be able to solve this problem. This problem may be solved using one of the software synchronization tools called - Semaphore.  Problem :   There is a shared buffer, a Producer and a Consumer. The buffer is used for putting any new item produced by the Producer. Consumer consumes items from the buffer. Now, the problem is - as the buffer is shared and two processes are accessing the buffer simultaneously, there may be inconsistency of data. So we need a synchronization method , such that, the storing of item within buffer by Producer, and the accessing of items from buffer by Consumer is synchronized, so that buffer data remains consistent. To achieve this we must ensure that -     Only one process at a time should access the buffer.     Producer can't produce if buffer is full.     Consumer can't consume if buffer is emp