From: Rajinder Yadav Date: 2009-10-20T10:46:02+09:00 Subject: Re: Threads terminating pawel wrote: > Why this simple program give no output, and terminates immidiatly > after its launched? There should be thread running and giving lots of > 'lala', am I right? > class Bar > def initialize > > end > def foo > Thread.new do > while true > puts "lala\n" > end > end > end > end > > b=Bar.new > b.foo > > > Hi Pawel, here is one example, see if you can follow it. class Bar def initialize( msg ) @msg = msg end def foo t_exit = Time.now.to_i + 3 while true puts @msg break if Time.now.to_i > t_exit sleep 0.5 end end end b1 = Thread.new{ Bar.new("x").foo } b2 = Thread.new{ Bar.new("o").foo } # here main thread waits for thread b1 and b2 to exit b1.join b2.join -- Kind Regards, Rajinder Yadav http://DevMentor.org Do Good ~ Share Freely