From: nobu.nokada@... Date: 2002-06-12T13:24:10+09:00 Subject: Re: threads question (newbie) 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