From: Robert Klemme Date: 2010-10-04T04:04:13+09:00 Subject: Re: Point me to help w/ multithreading in 1.9.2-p0 On 03.10.2010 20:30, Caleb Clausen wrote: > On 10/3/10, Robert Klemme wrote: >> On 03.10.2010 02:38, Caleb Clausen wrote: >>>> You can probably get away without the condition variable by just >>>> acquiring the lock (lock.synchronize) in the main thread before you >>>> create all threads and let all threads just synchronize with an empty >>>> block. >>> >>> I can't see any holes in this scheme, so it's probably the best idea. >> >> Even then it could be that some threads execute code before the >> synchronize and thus not start concurrently with other threads. > > But you made the synchronize statement at the very start of the thread > body, so this would seem to not be a concern in this case. The access to the cond var in the synchronize block was also the first statement in the thread body: Thread.new do lock.synchronize do until start cond.wait(lock) end end # work # return results [rand(10), rand(100)] end So there is really not that much difference. In practice this will usually not be a problem but from a more formal perspective it does not matter how many operations are performed before the synchronization - it still may be that a thread does not get CPU to get there. That's why I said that for a test scenario I would only bother to have all threads started concurrently if there was a lot of ramp up work to do. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/