From: Shashank Date Date: 2004-02-21T04:04:28+09:00 Subject: Re: threads and blocking --0-641480503-1077303864=:58892 Content-Type: text/plain; charset=us-ascii It may have to do with the threads get scheduled to run. For example, this will block like you expected: ruby -e "Thread.new{gets}; Thread.new{sleep(0.01);select nil}; Thread.new{puts 42}" Probably because the sleep in the second thread caused the first one to get its time slice. I was not surprised by the second example not blocking (if that is what you meant). Whichever thread gets scheduled will execute the "gets" (while blocking the other thread) but it immediately finds the string on the input stream and executes there by making way for the blocked thread. -- shanko "Ara.T.Howard" wrote: under which conditions will a blocking operation in a thread block the entire process? i thought i understood this but was suprised that ~ > ruby -e 'Thread.new{gets}; Thread.new{select nil}; Thread.new{puts 42}' 42 does not seem to block the entire process. i also was suprised that this worked: ~ > printf "4\n2\n" | ruby -e '[Thread.new{p gets.chop},Thread.new{p gets.chop}].map{|t| t.join}' "4" "2" i have been in situations before where one thread blocking has blocked my entire application and remember thinking to myself - "don't do blocking i/o from threads". but that appears to be too strong of a statement. can someone concisely enumerate the things to avoid? regards. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done =============================================================================== --------------------------------- Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. --0-641480503-1077303864=:58892--