mutex = Semaphore(1) ES = Semaphore(0) WS = Semaphore(0) int EC = 0, WC = 0, rope = 0 Process East mutex.wait() if (rope==5 or WC>0) { EC += 1 mutex.signal() ES.wait() } rope += 1 mutex.signal(); # cross mutex.wait(); rope -= 1 if (wc > 0 and rope == 0) { wc -= 1 wc.signal(); } else if (EC > 0 and rope < 5) { EC -= 1 ES.signal(); } else mutex.signal();