![]() wait(mutex) - Only one process can access the buffer at a time.so, the producer process executes wait(Empty) before producing any item. If the buffer is full producer process waits for the consumer process to consume items from the buffer. wait(Empty) - Before producing items, the producer process checks for the empty space in the buffer.Let's understand the above Producer process code : producer produces an item/data wait(Empty) The code for Producer Process is as follows : Let's look at the code of Producer-Consumer Process Wait() - The wait operation decreases the semaphore value by 1. ![]() Signal() - The signal function increases the semaphore value by 1. We will use the Signal() and wait() operation in the above-mentioned semaphores to arrive at a solution to the Producer-Consumer problem. Mutex - mutex is a binary semaphore variable that has a value of 0 or 1. mutex ensures that at any particular time only the producer or the consumer is accessing the buffer. Mutex is used to achieve mutual exclusion. The Empty variable is initially initialized to the BUFFER-SIZE as initially, the whole buffer is empty. The Empty variable is used to track the empty space in the buffer. It is initialized to 0 initially as initially no space is filled by the Producer process. The full variable is used to track the space filled in the buffer by the Producer process. ![]() semaphore variables are used to achieve `Process Synchronization. Semaphores are variables used to indicate the number of resources available in the system at a particular time. To solve the Producer-Consumer problem three semaphores variable are used :
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |