Professional Documents
Culture Documents
Semaphore
Semaphore
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
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