The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+29 votes
4.6k 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
asked in Operating System by Veteran (59.6k points)
edited by | 4.6k 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 

+5
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.................
+1
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.
0

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 

+1

 AakS

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!!??
+1
yes.. we need to find a sequence such that the largest number of processes can reside in the CS at the same time..
0
Thanks this is fastest reply I have ever received
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 ?

 

 

5 Answers

+46 votes
Best answer

Answer is (D).
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.

answered by Active (2.1k points)
edited by
0

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

This is not mentioned rt?

+8

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".

+3
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.
+1
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 .

Which contradicts. 

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 ??
+2 votes
10 i.e.  ans D)
answered by (47 points)
+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
+1 vote
option d) none

all 10 processes can enter the critical section
answered by Active (2.3k points)
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
0 votes

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 

Answer =10

answered by Junior (719 points)
–3 votes
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.
answered by Active (1k points)

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,613 questions
48,609 answers
155,804 comments
63,796 users