Next: About this document
Up: No Title
Previous: Semaphores
var mutex = 1 : semaphore ; {binary}
space = N : semaphore ;
cans = 0 : semaphore ;
Process PRODUCER;
loop
{pick can off crate}
P(space) ; {wait for slot in the coke machine}
P(mutex) ; {get mutual exclusion}
{put one can in machine}
V(mutex} ; {release mutual exclusion}
V(cans} ; {signal cans available}
end ;
Process CONSUMER;
loop
P(cans) ; {wait for any cans}
P(mutex) ; {obtain mutual exclusion}
{take one can}
V(mutex) ; {release mutual exclusion}
V(space) ; {signal space available}
end ;
- Solution holds for multiple producers and consumers
- Does order of P and V matter ?
- Does it matter is can is consumed before or after V in consumer ?
Omer F Rana
Tue Feb 11 19:19:09 GMT 1997