2 # The Dining Philosophers - thread example
8 N=9 # number of philosophers
31 if not $forks[(n+1)%N].try_lock
32 $forks[n].unlock # avoid deadlock
36 $state[(n+1)%N*2] = ?|;
41 $state[(n+1)%N*2] = ?-;
45 $forks[(n+1)%N].unlock
50 Thread.start(n){|i| philosopher(i)}