in Operating System
478 views
2 votes
2 votes
In certain countries, when two people meet they bow to each other. The protocol is that one of them bows first and stays down until the other one bows. If they bow at the same time, they will both stay bowed forever. Write a program that does not deadlock.
in Operating System
478 views

1 Answer

0 votes
0 votes

I think the following program would suffice: 

bowing = [false, false]

bowing[i] = true;

if(bowing[j]==true) bowing[i] = false;

 

4 Comments

I thought that "If they both bow at the same time, they will both stay bowed forever" was the deadlock condition which had to be avoided. How are you avoiding deadlock through your code and what is the deadlock condition? @GMPrakhar

0
0
Deadlock condition can be thought of as the situation where we use infinite wait, for example

while(bowing[j]);

bowing[i] = false;

In my solution, I avoided the infinite wait, confirming with the question's language.
0
0
semafore s=1
pi
wait(s);
bow();
signal(s);
}
0
0

Related questions