From: Ashley Moran Date: 2006-04-23T20:26:09+09:00 Subject: Re: How do threads and join work? On Apr 23, 2006, at 11:06 am, Pat Maddox wrote: > running = true > t = Thread.new do > print "Thread started\n" > while(running); end > print "Thread finished\n" > end > > t.join > puts "After join" > running = false > puts "Program finished" > > The paragraph I quoted makes me think that it should print "Thread > started...After join...Thread finished...Program finished" It joins > the thread and continues processing, setting running to false, which > causes the thread's loop to end. Also not that it could say "Program > finished...Thread finished", I don't think there's a way to know for > sure. Your thread never actually finished, because you joined on it before you set the value of running to false, so your code blocks at that point. You need to swap the last lines like this: running = true t = Thread.new do print "Thread started\n" while(running); puts "running = #{running}"; sleep 1; end puts "running = #{running}"; print "Thread finished\n" end sleep 5 puts "Before join" running = false t.join puts "After join" puts "Program finished" I added two things into the while loop: a sleep so you don't run your CPU at 100% and a ticker. Ashley