1,195 views
5 votes
5 votes

My question is little different.

Each Process Pi, i = 1....9 is coded as follows

repeat
    P(mutex)
    {Critical section}
    V(mutex)
forever

The code for P10 is identical except it uses V(mutex) in place of P(mutex). What is the largest number of processes that can be inside the critical section at any moment?

If instead of mutex a semaphore would have been used, then was it possible that p1, p2 , p3 or any other process instead of process p10 could have opted out while all are in the critical section.?
My doubt started from the following note which I read from a source:
"Mutex can be released only by thread that had acquired it, while you can signal semaphore from any other thread (or process), so semaphores are more suitable for some synchronization problems like producer-consumer."

1 Answer

1 votes
1 votes

Answer is D 
If
initial value is 1//execute P1 or P10 first  
If
initial value is 0, P_10 can execute and make the value 1. 
since
the both code (ie p1 to p9 and p10)can be executed any number of times and code for p10 is 
 

repeat
{
    v(mutex)
    C.S.
    V(mutex)
}
forever 

now let me say P1 is in c.s  
then p10 comes executes the CS(
up on mutex) 
now P2 comes (down on mutex) 
now P10 moves out of CS (again binary semaphore will be 1 ) 
now P3 comes (down on mutex) 
now P10 come (
up on mutex) 
now P4 comes (down on mutex)  
so if we take p10 in out of CS recursively all 10 process can be in CS at same time 
using Binary semaphore only

Related questions

0 votes
0 votes
0 answers
2
amitqy asked Nov 21, 2018
987 views
0 votes
0 votes
0 answers
4
jatinmittal199510 asked Jan 15, 2017
432 views
Does Mutex provide Bounded Waiting solution ? (since it can lead to deadlock state, and I studied somewhere that if there is deadlock then we cannot assure Bounded Wait...