- 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.10;
Figure 6.10:
The structure of the producer process.
|
- The code for the consumer process is shown in Fig. 6.11;
Figure 6.11:
The structure of the consumer process.
|
Figure 6.12:
The producer-consumer problem using semaphores.
|
Cem Ozdogan
2011-02-14