- We assume that the pool consists of buffers, each capable of holding one item. The mutex semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the value 1.
- The empty and full semaphores count the number of empty and full buffers.
- The semaphore empty is initialized to the value n.
- The semaphore full is initialized to the value 0.
- The code for the producer process is shown in Fig. 6;
Figure 6:
The structure of the producer process.
|
- The code for the consumer process is shown in Fig. 7;
Figure 7:
The structure of the consumer process.
|
Figure 8:
The producer-consumer problem using semaphores.
|
Cem Ozdogan
2010-04-06