From: Alex Zunega Date: 2009-09-03T10:47:47+09:00 Subject: Threads - running something in background Hey guys, I've been studying Ruby for some weeks now but when it comes to threads, I know that I am totally unskilled. I am trying to build a class which is able to keep updating itself every X seconds after being initialized. In general terms it would work like this: ---- class Threading_Test attr_accessor :i def initialize @i = 0 @j = 0 neverstop = false t1 = Thread.new do while neverstop == false do sleep 0.1 #here's the the problem. @i = @i + 1 end end t1.run puts "I am ready and I keep updating myself. Or not..." end end ---- The problem occurs when I try to add this "sleep 0.1" into the thread block. The thread only seems to become active when I ask for the @i value. I know that there might be other ways to implement that, but i think that it would fit my code better that setting up a Cron task to do so. Thank you all for the help. -- Posted via http://www.ruby-forum.com/.