Semaphores for Solving Coordination Problems
Involving Multiple Processes |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
Note: With this protocol B1 will always be completed before A1 (which is not required).
Producers
Consumers
Semaphores
Producers
Consumers
sem_wait(available)
and sem_wait(key)
, another process gets access
to the warehouse and there is only a single product in the
warehouse?
available
The Better Producer Protocol
The Worse Producer Protocol
Note: This protocol is worse because a consumer may stop waiting on available product before it can get the key (i.e., be unblocked and then immediately blocked again).
The Correct Consumer Protocol
A Consumer Protocol that is not Deadlock-Free
A consumer can get the key when no product is available and, since the key is no longer available, no producer will be able to add one.
Semaphores and Shared Variables
Writers
Readers