作業系統›Ch6 行程同步(Process Synchronization)第 29 題/共 32 題
29. Semaphore、Producer-Consumer
#OS-06-029易SemaphoreProducer-Consumer
The right side shows a solution to the producer-consumer problem with buffers using three semaphores, where empty=n, mutex=1, and full=0 at the initial state. Some variables are missing in the consumer program. What are they?
The structure of the consumer process:
do {
wait(V1);
wait(V2);
// remove an item
signal(___);
signal(___);
// consume the item
} while (TRUE);
The structure of the producer process:
do {
// produce an item in nextp
wait(empty);
wait(mutex);
// add nextp to buffer
signal(mutex);
signal(full);
} while (TRUE);
📄 中央111
▤完整推導請見《WH 資工筆記 · 作業系統》Ch6 行程同步(Process Synchronization)