Pass value into a thread : Thread.new « Threads « Ruby





Pass value into a thread


n = 1
while n <= 3
  # Get a private copy of the current value of n in x
  Thread.new(n) {|x| puts x }
  n += 1
end

 

Related examples in the same category

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