3,240 views

1 Answer

0 votes
0 votes
Let Binary semaphore s initialized to 1 is shared among n processes .

Below is the code snippet to illustrate Mutual Exclusion

Let Suppose Pi process wants to enter the critical section so it will execute below code and later on if any other process wish to enter critical section it can't do so as wait(s) is 0 now .Once the Pi process signals s only then other process will be able to enter critical section thereby achieving Mutual exclusion.

do(

wait(s);

//Critical Section

signal(s);

}while(true);

 

Hope if this clarifies.

Related questions

0 votes
0 votes
0 answers
1
akash.dinkar12 asked Mar 20, 2019
512 views
Explain why implementing synchronization primitives by disabling interrupts is not appropriate in a single-processor system if the synchronization primitives are to be us...