From: Sam Duncan Date: 2011-07-29T05:32:11+09:00 Subject: Re: long loops inside threads Are you join'ing the thread? If not your main thread is likely to exit before the counting thread has. > cat /tmp/test.rb require 'thread' t = Thread.new { count=0 while count < 10000 do puts "x" count +=1 end } t.join > ruby /tmp/test.rb |wc -l 10000 > ruby /tmp/test.rb |wc -l 10000 > ruby /tmp/test.rb |wc -l 10000 Sam On 29/07/11 08:12, Miguel Angel Nieto wrote: > Hi, > > I have a newbie question :) > > If I run the following code outside a thread: > > count=0 > while count< 10000 do > puts "x" > count +=1 > end > > I get 10000 'x'. > > But, if I run the same code inside a thread, I receive different number > of 'x' on each execution: > > 7932 > 4305 > 4431 > > What I'm doing wrong? > > I need to execute the same command inside a thread 10000 times! :) > > Thank you. >