From: MenTaLguY Date: 2008-02-21T03:33:23+09:00 Subject: Re: Ruby 1.9, threads and FreeBSD 5 On Wed, 20 Feb 2008 22:09:59 +0900, Eric Jacoboni wrote: > 1.upto(10) do # 10 threads ping > Thread.new do > mutex.synchronize do > pong.wait(mutex) > puts("Ping...") > ping.signal > end > end > end > > pong.signal # Go! Your code is buggy: there is a race condition such that the initial #signal can get called before any corresponding #waits. That it superficially appeared to work consistently with 1.8 was an accident of thread scheduling. Adding a 'sleep' beforehand, as another poster suggested, makes it more likely to work but does not actually fix the bug. The correct approach is to use a synchronization primitive which queues notifications, for example a semaphore or a queue, rather than a condition variable. A queued notification can't get "missed" like this. -mental