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

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;

 

Related questions