From: Robert Klemme Date: 2010-03-09T17:12:08+09:00 Subject: Re: question on threads 2010/3/9 Jean G. : > Hello, > > count = 0 > threads = [] > > 10.times do |i| >  threads[i] = Thread.new do >    sleep(rand(0.1)) >    Thread.current["mycount"] = count >    count += 1 >  end > end > > threads.each {|t| t.join; print t["mycount"], ", " } > > > For the code above, why the output numbers are random, rather than > from 0 to 9 by increasing? Because there are no guarantees about thread scheduling. Btw, your code is not really thread safe since you access a shared resource without proper synchronization (although it might work on some Ruby platforms). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/