J
Jean G.
Hello,
count = 0
threads = []
10.times do |i|
threads = Thread.new do
sleep(rand(0.1))
Thread.current["mycount"] = count
count += 1
end
end
threads.each {|t| t.join; print t["mycount"], ", " }
For the code above, why the output numbers are random, rather than
from 0 to 9 by increasing?
Thanks.
count = 0
threads = []
10.times do |i|
threads = Thread.new do
sleep(rand(0.1))
Thread.current["mycount"] = count
count += 1
end
end
threads.each {|t| t.join; print t["mycount"], ", " }
For the code above, why the output numbers are random, rather than
from 0 to 9 by increasing?
Thanks.