From: Shashank Date Date: 2002-06-12T15:01:29+09:00 Subject: Re: threads question (newbie) Ok, then, replace the block 10.times { |i| commands << "ping 1.1.1.1 -n 10 -w 1000 > junk#{i}.txt" } with the block: 3.times { |i| commands << "dir /s > nul" commands << "ping 1.1.1.1 -n 10 -w 1000 > nul" commands << "find \"nokada\" %windir%\\*.* > nul" } and you will get the same results !! But to get all the 9 threads to start simultaneously, I had to bump sleep(0.01) to sleep(1). I guess, I did not understand the dependency on "winsock limitation". I am sure, we will be able to repeat the experiment without the ping (or any commands dependant on winsock); Thanks, -- Shanko wrote in message news:200206120424.g5C4O9214711@sharui.nakada.kanuma.tochigi.jp... > Hi, > > At Wed, 12 Jun 2002 11:21:17 +0900, > Shashank Date wrote: > > This is using Ruby 1.6.7 on Windows (mswin32). > > > > The following program without the sleep(0.01) stmt > > seems to hang/stall after creating 3 threads until one thread is done. > > Thus it takes over 35 seconds to finish. > > IO multiplexing works with only sockets in mswin32 -- this > comes from winsock limitation. And new thread would get the > control immediatly, so `#{myCmd}` blocks before the main thread > would run again. > > > But with the sleep stmt it starts all the 10 threads concurrently and the > > entire > > process is over in about 10 to 12 seconds as expected. > > In that case, the main thread gets the control before the > backticks. And invoked commands can run simultaneously. > > With Thread.stop/wakeup it may also work. > > > threads = [] > > for command in commands > > threads << Thread.new(command){ |myCmd| > Thread.stop > > `#{myCmd}` > > } > > end > Thread.exclusive {threads.each {|aThread| aThread.wakeup}} > > threads.each { |aThread| aThread.join } > > puts `echo %TIME%` > > -- > Nobu Nakada >