Please take a look on the following pseudo-code:
boolean blocked[2]; int turn; void P(int id) { while(true) { blocked[id] = true;
Is this homework, or some embedded platform? Is there any reason why you can't use pthreads or Win32 (as relevant) synchronisation primitives?