threads and blocking

Discussion in 'Ruby' started by Ara.T.Howard, Feb 20, 2004.

  1. Ara.T.Howard

    Ara.T.Howard Guest

    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
    ===============================================================================
     
    Ara.T.Howard, Feb 20, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendra Gunawan
    Replies:
    1
    Views:
    12,596
    Allan Herriman
    Apr 8, 2004
  2. Andre Kelmanson

    blocking i/o vs. non blocking i/o (performance)

    Andre Kelmanson, Oct 10, 2003, in forum: C Programming
    Replies:
    3
    Views:
    940
    Valentin Tihomirov
    Oct 12, 2003
  3. nukleus
    Replies:
    14
    Views:
    838
    Chris Uppal
    Jan 22, 2007
  4. Christian
    Replies:
    5
    Views:
    738
    Esmond Pitt
    Dec 2, 2007
  5. Serge Savoie
    Replies:
    4
    Views:
    272
    Serge Savoie
    Oct 1, 2008
Loading...

Share This Page