From: 7stud -- Date: 2011-05-12T07:52:34+09:00 Subject: Re: Creating and Executing New Threads Dan King wrote in post #998095: > I expected the script below to do the following: > > (1) spawn a new thread > (2) connect to a server > (3) read the data transmitted by the server > (4) close the connection. > (5) repeat 1-4 > > While the script works, it does NOT spawn a new thread for each > connection. Does anyone why that is the case? Thanks. > threads = [] 10.times do |i| threads << Thread.new(i) do |thread_num| sleep(rand(3)) puts thread_num end end threads.each { |t| t.join } --output:-- 1 2 3 6 5 4 9 0 7 8 Read the first paragraph here: http://rubylearning.com/satishtalim/ruby_threads.html -- Posted via http://www.ruby-forum.com/.