manipulate variables from the outer scope : Thread.new « Threads « Ruby






manipulate variables from the outer scope


x = 1
y = 2
thread3 = Thread.new do
  sleep(rand(0))
  x = 3
end

sleep(rand(0))
puts x

 








Related examples in the same category

1.Create threads in a while loop
2.Pass value into a thread
3.Use upto to create 3 threads
4.Access the thread-local data from outside
5.True local variables (not accessible from outside)