rope = Semaphore(5) east = Semaphore(1) west = Semaphore(1) west.wait() mutex.wait() rope.wait() count++ # cross rope.signal() mutex.signal() if count == 100 { count = 0 east.signal }