in Operating System edited by
1,999 views
3 votes
3 votes

Consider program for P1  and P2:

Here, m and n are binary semaphore variables whose values are initially initialized to 1. x and y are shared resources whose values are initialized to 0.
Which of the following holds by above processes?

A :- Deadlock and no mutual exclusion

B :-Deadlock and race condition

C :-No deadlocks and no race condition

D:- Race condition and no deadlock

in Operating System edited by
2.0k views

4 Comments

Yeah .They said that x and y are shared resources.So it means x and y are accessed it critical section. And now both of them can enter critical section at same time(one will use x and other will use y ,but both are entering in critical section.).Hence ME not satisfied.This is what they told.

But i dont know if this is a valid assumption.What if  x and y has separate critical section entry exit code?I am not sure if this is a valid case though
0
0
Yes I also assumed x and y will have separate CS. So here doubt arises that all shared variables will be accessed in the same CS?
0
0
Not sure;I have the same doubt.Lets wait.Someone will solve this doubt:)
0
0

3 Answers

1 vote
1 vote

P1()
1.wait(m)
2.x++
context switch

P2()
1.wait(n)
2.y++
3.wait(m) // waiting for m to became 1
context switch

P1() // arraive again
3.wait(n)// waitning for n to become 1

1.conclusion – it create deadlock 
2.conclusion – there is mutual exclusion

 

ANS – option B

 

0 votes
0 votes
P1 will execute wait(m) & P2 will execute wait(n) so both m & n will become 0. So when P1 will execute wait(n) & P2 will execute wait(m). They both will go to deadlock. Here, no mutual exclusion took place.

4 Comments

Mutual Exclusion : At least one resource must be held in a non sharable mode; that is, only one process at a time can use the resource. If another process requests that resource, the requesting process must be delayed until the resource has been released.

you are right, but here the problem is with semaphores, can you explain why mutual exclusion is not achieved here?

0
0
edited by

above ans is correct for deadlock but there is mutual exclusion for sure☺

 
 
 
 
2
2

there is no relation of mutual exclusion and semaphores.

as u said in mutual exclusion resource cant be shared here that resource is some lines of code known as critical section

and i didn’t said that mutual exclusion is not achived here...there is mutual exclusion and thats also posiblity of dead lock which in this case has occured

0
0
0 votes
0 votes
The answer should be Deadlock and no race condition. The given options do not match the answer.

There exists a deadlock scenario namely

P1 and P2 both execute, both acquire m and n respectively. Both execute their respective increment statements and then both execute the wait statements trying to acquire each others acquired semaphores which creates a deadlock scenario.

There does not exist a Race condition since there is no scenario in which both P1 and P2 can execute increments of the same variable i.e x or y at the same time.

1 comment

This is the correct answer, since in case of mutual exclusion, we need the condition that 2 or more threads are trying to modify the same shared location at the same time!

0
0

Related questions