Bug with fifos in Linux?

Discussion in 'Ruby' started by Derek Lewis, Dec 12, 2003.

  1. Derek Lewis

    Derek Lewis Guest

    I don't know if this is a new bug, known bug, or some sort of feature...
    When I try to open a fifo, the entire ruby interpreter locks until
    something else opens the other "end" of the fifo. Here's some example
    code:

    FIFO_FILE='/tmp/rubyfifo'
    `mkfifo "#{FIFO_FILE}"` unless test(?e, FIFO_FILE)

    thread = Thread.new {
    puts "Opening fifo for writing"
    File.open(FIFO_FILE, 'w') { |file|
    puts "Starting write loop"
    while true
    puts "Thread is running"
    sleep 1
    file.puts "Thread is running"
    end
    }
    }

    puts "Opening fifo for reading"
    File.open(FIFO_FILE, 'r') { |file|
    puts "Reading from fifo"
    file.each_line { |line|

    puts "Read from fifo: #{line}"
    }
    }


    The only output I see from this is "Opening fifo for writing".
    If the thread is changed to:

    thread = Thread.new {
    puts "Starting loop"
    while true
    puts "Thread is running"
    sleep 1
    end
    }


    Then instead, I see this output:
    Starting loop
    Thread is running
    Opening fifo for reading

    And I don't see "Thread is running" until I execute this in another
    shell:

    cat > /tmp/rubyfifo

    As soon as I close the cat, the ruby program exits nicely.


    Derek Lewis

    ===================================================================
    Java Web-Application Developer

    Email :
    Cellular : 604.312.2846
    Website : http://www.lewisd.com

    "If you've got a 5000-line JSP page that has "all in one" support
    for three input forms and four follow-up screens, all controlled
    by "if" statements in scriptlets, well ... please don't show it
    to me :). Its almost dinner time, and I don't want to lose my
    appetite :)."
    - Craig R. McClanahan
     
    Derek Lewis, Dec 12, 2003
    #1
    1. Advertisements

  2. Derek Lewis

    ts Guest

    D> I don't know if this is a new bug, known bug, or some sort of feature...

    Something which is intentional can't be called a bug :)

    D> When I try to open a fifo, the entire ruby interpreter locks until
    D> something else opens the other "end" of the fifo. Here's some example
    D> code:

    You can use IO::NONBLOCK with IO::WRONLY or IO::RDONLY


    Guy Decoux
     
    ts, Dec 12, 2003
    #2
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.