Semaphores
Semaphores
Semaphores
7.1
Background
7.2
n processes all competing to use some shared data. Each process has a code segment, called critical section, in
which the shared data is accessed.
Structure of process Pi
repeat entry section critical section exit section reminder section until false;
Operating System Concepts 7.3
Semaphores
Semaphore is a synchronization tool which can be used to deal with the critical-section problem. A semaphore is a protected variable whose value can be accessed and altered only by the operations P (wait) and V (signal) and an initialization operation we shall call semaphoreinitialize.
7.5
7.6
Starvation
indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended. processes will not suffer indefinite postponement.
Example: Example: Deadlock Deadlock and and Starvation Starvation (Cont.) (Cont.)
Step 1:
Dining-Philosophers Problem:
Rice
7.12
Dining-Philosophers Problem
Solution:
Present each chopstick by a semaphore. A philosopher tries to grab the chopstick by executing a wait operation on that semaphore. She releases her chopsticks by executing the signal operation on the appropriate semaphores.