I think the following program would suffice:
bowing = [false, false] bowing[i] = true; if(bowing[j]==true) bowing[i] = false;
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