edited by
2,533 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

edited by

3 Answers

1 votes
1 votes

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

Related questions

1 votes
1 votes
1 answer
1
6 votes
6 votes
1 answer
3
Shamim Ahmed asked Jan 13, 2019
1,424 views
Let S be a binary semaphore variable, S=0What will be the value of S when following operations are performed:-2P, 4V, 5P, 2P, 8V, 3P, 2V ?