CREATE OWN LIBRARY

Sequential execution of process in Binary Semaphore (mutex)

 

Advantage of binary semaphore mutex is processes execute sequentially and also maintain an order.

 

Example

 

Mutex a, b initially a = 1, b = 0;

 

P0

While (True)

{

P(a); //down a

Print ("1");

V(b); // up b

}

P0

While (True)

{

P(b); //down p

Print ("0");

V(a); // up a

}

 

So, whatever the order you run P0 first and P1 second or P1 first and P0 second if it runs the continuous way the result will be 10101010......

 

Even the process contains two mutexes but it is also in mutual exclusion.