8k views

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

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

The code for $P_{10}$ 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?

1. $1$
2. $2$
3. $3$
4. None

edited | 8k views
+1

y not c answer  ??  one process is executing critical section. all other are waiting. when P10 comes and increases semaphor value then the first process waiting in queue and P10 both comes into critical section. So there will be max 3 processes. this is correct explanation beacuse p10 only V not P any time it will only increase the value of a semaphore .... kindly correct me if m wrong

+6
it asks for "largest". You can see the given answer- it shows how 10 processes can enter CS. And 10 is > 3. So, C is wrong.
+1
okey ... thx.................
+3
Let mutex is x and initially it is what ever let 1
Then p0 first enter , now x is 0 ,now p10 will enter again x will be 1 ...now p1 will enter so x will again 0, now p10 will exit so again x will be 1... this situation can be occurs many times ..so all 10 processes can be in CS simultaneously.
+1

whether we take mutex initially 0 or 1, all 10 processes can be inside within critical section on the maximum side.

If we take P(mutex) in code of P10 in last, i.e.,

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

then if mutex is 0 initially then max 2 processes can be in CS and if mutex initially 1 then 3 process at max in CS

+3

The code for P10 is identical except it uses V(mutex) in place of P(mutex).

It does not say that the V(mutex) and P(mutex) are switched in P10. Only V(mutex) is written instead of P(mutex).

So the code becomes,

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

0
Means we are assuming that processes can execute in any sequence as there is no sequence mentioned!!??
+2
yes.. we need to find a sequence such that the largest number of processes can reside in the CS at the same time..
+1
0

@MiNiPanda

https://gateoverflow.in/2264/gate1997-6-8?show=8931#c8931

Even though it had been "swap P and V for P10" , we can run processes any number of times r8 ?

0

nothing is mentioned about sequence here then why we are assuming 3

https://gateoverflow.in/66221/go2017-os-9

0
0

i think you didnt give the test anyways for this question answer is 3

+1

The difference is in "vice versa".

In this question(Gate question), P10 is like V(mutext) CS V(mutex) but in your question it is V(mutex) CS P(mutex).

If you try to check now, be it any sequence, you cannot fit more than 3 process when mutex=1.

If initial value is $1$//execute $P_1$ or $P_{10}$ first
If initial value is $0$, $P_{10}$ can execute and make the value $1$.
Since the both code (i.e. $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 $P_1$ is in c.s
then $p10$ comes executes the $CS$ (up on mutex)
now $P_2$ comes (down on mutex)
now $P_{10}$ moves out of CS (again binary semaphore will be 1 )
now $P_3$ comes (down on mutex)
now $P_{10}$ come (up on mutex)
now $P_4$ 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.

by
edited
0

"since the both code (ie p1 to p9 and p10)canexecuted any number of times

This is not mentioned rt?

+11

Arjun sir repeat forever itself means that the code can run any number of times :)
this type of syntax is used by Verilog, "standardized as IEEE 1364, is a hardware description language (HDL) used to model electronic systems".

+5
Yes you are right. I was actually swapping V and P for P10. Misread the question.
0
yes all 10 qustion can go into the critical section but in the question they have asked about how many max no process present in the critical section "at any instant" so answer shul be 3
+1
sorry by mistake i type Question instead of process
0
The answer is given for "any instant" only.
+4
Mutex are not Binary Semaphores so I don't know why all the answers are treating it like one. Is it just to get the answer that makes more sense? Mutex are property of task that acquires it so p10 cannot signal/release the mutex using its first v(mutex)  function. In fact it will return and error when it tries to do so and the mutex will continue to be with process p1 to p9 whosoever has acquired the lock. or be free to acquired. Technically p10 will always throw an error and process P1 to P9 will be perfectly synchronized allowing only one process to be in its critical section everytime.

I did some research on some sites and in c# releaseMutex function does throw an exception if a process not acquiring it currently tries to release it.  So shouldn't P10 be completely out of question here? Please correct me if I am wrong but the answer should be (a).

@Arjun sir. Can you clear this up please? Thank you.
0
But by using binary semaphore, mutex value can be either 0 or 1 ri8? @arjun sir
0

There should be

Bounded waiting .

0

@Arjun Sir, Please clarify- How can we use mutex like binary semaphore here? Mutexes don't allow that. This has been already explained by Vaibhav Raj Singh above too.

0
if we change code for execution p10 is

repeat

v(mutex)

c.s

p(mutex)

forever

so how many process may maximimin c.s ??
+3

Mutex stands for Mutual Exclusion, it does'nt allow more than one process to enter into CS...

I don't know why everyone is treating Mutex as Binary semaphores, they're completly different things

https://stackoverflow.com/questions/62814/difference-between-binary-semaphore-and-mutex

+2

0

@Arjun sir what if there is P(mutex) in last line of P10? will the answer be 3? please correct me if wrong

+1

Q1:@kalpish Isn't this the case with mutex that the only process can give signal to mutex which has applied wait on the mutex ?

I have understood your explanation. But I have read this concept from different sources.Like  https://www.tutorialspoint.com/mutex-vs-semaphore

Q2:Here are we using mutex or binary semaphore?

Q3: If we are using mutex then what is the difference between mutex and binary semaphores?

@arjun sir

@abhishekmehta4u

+1

@Akash Kumar Roy Exactly! thats what i was also thinking that why everyone is treating Mutex as Binary semaphores, they're completly different things.

https://stackoverflow.com/questions/62814/difference-between-binary-semaphore-and-mutex

10 i.e.  ans D)
+1
but option D is none which means none of the process can enter it .Here it is none not the None of the the above.please Clarfy
0
Well I agree with you.its just like misguiding students
option d) none

all 10 processes can enter the critical section
0
how 10 is possible
+1
see it is given "The code for P10 is identical except it uses V(mutex) instead of P(mutex)"
it means for P10 code is
V(mutex)

{critical section}

V(mutex)
so everytime p10 is entering any process can enter, also p10 repeats forever.
0
The question only tells about replacing P(mutex) with V(mutex) so P10 only has V(mutex) in both places
+1 vote

Here when Pi ,where i=1,2,.....,9 so

repeat
p(mutex)
{Critical section}
v(mutex)
forever 

in this code P means down operation and V means up operation , initially  mutex value=1; now for a down operation it will be decreased by 1 which will be 0 now it will check the value is < 0 or > 0 we are watching that value is 0 means process can enter in to the CS. (HERE P1 IS IN C.S) other processes will come in order to enter into the CS but they again decrease the value by 1 which means the value will be less than 0, so all the process p2,p3,p4,p5,p6,p7,p8,p9 will be blocked. and stored in a queue.

NOW

repeat
V(mutex)
{Critical section}
P(mutex)
forever     p10, will execute it will perform V means UP operation so it will increase the value by 1, and because of this one process will come outfrom the queue from(p2 to p9 any process can come here we are using queue so it will come in FIFO order) again UP again one process come out this will continue...... so in last all the processes in the  C.S 

+1
In P10 instead of P(mutex) there should be V(mutex) then the answer should be 10 else the answer will be 3 in your case since P10 will perform down operation in last line
+1
Alakhator , Could you please explain how we would get 3 for that case?

maximum 10 processes can enter in the crictical section at a time.
hence option D should be the right choice.

if the code for the process 10 would be like

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

And if code would be like for Process 10
repeat
P(mutex)
{Critical section}
P(mutex)
forever

+1

Rajesh Panwar , Could you please explain how we would get 3 for the following case?

  if the code for the process 10 would be like

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

0

one process is executing critical section. all other are waiting. when P10 comes and increases semaphor value then the first process waiting in queue and P10 both comes into critical section. So there will be max 3 processes.

credits : @

(D) Consider code for i= 1 to 9 Initially mutex value set to 1, so it can allow only 1 process at a time. Now p1 enter into critical section and by this time remaining all are in block state. (i.e blocked processes= 2,3,4,5,6,7,8,9). But consider code for 10th process, it tells that unblock any process because it contain operation. Because of this it can unblock the processes and send it to the critical section. By doing this all processes can enter into critical section. So, finally there are 10 processes at maximum can enter into critical section. Alternative Way- There is loop which runs forever So P10 runs forever. And it has capability to put all other processes to Critical Section. Moreover they Asked Maximum Number of process that can be Present at critical Section So Answer is 10. Option (D) is correct.

option C

one process is executing critical section. all other are waiting. when P10 comes and increases semaphor value then the first process waiting in queue and P10 both comes into critical section. So there will be max 3 processes.
by
0
I think 3 will be the answer for the processes that can b in cs at same time but they r asking for processes at any moment of time plz crct me if I'm wrong