Example Program: Dining Philosophers NUM_PHILOSOPHERS = 5; THINKMAX = 6; EATMAX = 2 def philosopher(n, forks, display): f1, f2 = n, (n+1)% NUM_PHILOSOPHERS display.setPhil(n, "thinking") while 1: #infinite loop time.sleep(randint(0,THINKMAX)) display.setPhil(n, "hungry") forks[f1].wait() display.setFork(f1,"inuse") time.sleep(1) forks[f2].wait() display.setFork(f2, "inuse"); display.setPhil(n, "eating") time.sleep(randint(1,EATMAX)) display.setPhil(n, "thinking"); display.setFork(f2,"free") forks[f2].signal() display.setFork(f1,"free") forks[f1].signal() d = DPDisplay(NUM_PHILOSOPHERS) forks = [] for i in range(NUM_PHILOSOPHERS): forks.append(Semaphore(1)); d.setFork(i,"free") for i in range(NUM_PHILOSOPHERS): thread.start_new_thread(philosopher, (i,forks, d)) d.pause()