You are on page 1of 4

Semaphore Solution

Semaphore is a synchronization tool. Extension of the mutual locks solution but there is differences It involves the execution of two atomic solutions, Wait() and Signal()

Execution
Wait() The counter is initalized to 1: Wait begins and the counter decreases, execution continues. The counter is at 0: The thread is suspended and placed in a queue Signal()

No waiting threads:
The counter that was on 0 is now increased to 1, the thread starts the wait process again Threads waiting: The counter must be on 0, one thread is chosen to leave the queue

Problems with semaphores


If all philosophers decided to eat at the same time a deadlock would occur resulting in starvation which is the indefinite blocking. A process will never be moved from the queue in which it was suspended in. To avoid this:

Don't allow all philosophers to eat at once

Make is so the philosophers have to pick up the chopsticks in the critical section , where as you know only one process can be executing at a time Alternate the choice of the first chopstick

You might also like