From: 7stud -- Date: 2009-09-03T11:55:38+09:00 Subject: Re: Threads - running something in background Alex Zunega wrote: > Hey guys, > > I've been studying Ruby for some weeks now but when it comes to > threads, I know that I am totally unskilled. > Also, you should realize that the @i in the class and the @i in the thread are the same variable. Therefore, things like this can happen: class Updater attr_accessor :i def initialize @i = 0 Thread.new do loop do sleep(0.3) @i += 1 puts "....#{@i}" end end end end upd = Updater.new 3.times do sleep(2) puts upd.i upd.i = 0 #<-----****** end --output:-- ....1 ....2 ....3 ....4 ....5 ....6 6 ....1 ....2 ....3 ....4 ....5 ....6 ....7 7 ....1 ....2 ....3 ....4 ....5 ....6 6 -- Posted via http://www.ruby-forum.com/.