Basic Ruby Threads in Action : Ruby Threads « Threads « Ruby






Basic Ruby Threads in Action

threads = []

10.times do
  thread = Thread.new do
    10.times { |i| print i; $stdout.flush; sleep rand(2) }
  end

  threads << thread
end

threads.each { |thread| thread.join }
          

 








Related examples in the same category

1.Run this block in a new thread
2.Get the value returned from a thread
3.Sleep a thread