Please take a look on the following pseudo-code:
boolean blocked[2]; int turn; void P(int id) { while(true) { blocked[id] = true;
Maybe you need to declare blocked and turn as volatile, but without specifying the programming language there is no way to know.