Ruby 1.9, threads and FreeBSD 5

Discussion in 'Ruby' started by Eric Jacoboni, Feb 20, 2008.

  1. Hi,

    Considering the following theory code:

    require "thread"

    ping = ConditionVariable.new
    pong = ConditionVariable.new
    mutex = Mutex.new

    1.upto(10) do # 10 threads pong
    Thread.new do
    mutex.synchronize do
    ping.wait(mutex)
    puts("Pong...")
    pong.signal
    end
    end
    end

    1.upto(10) do # 10 threads ping
    Thread.new do
    mutex.synchronize do
    pong.wait(mutex)
    print("Ping...")
    ping.signal
    end
    end
    end

    pong.signal # Go!

    Thread.list.each { |t| t.join if t != Thread.main }


    This code works as expected with Ruby 1.8 on FreeBSD and OS X :

    % /usr/bin/ruby ping_pong_cond.rb
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...
    Ping...Pong...


    But it blocks with Ruby 1.9 on both OS :

    % ruby ping_pong_cond.rb
    ^Cping_pong_cond.rb:30:in `join': Interrupt
    from ping_pong_cond.rb:30:in `block in <main>'
    from ping_pong_cond.rb:30:in `each'
    from ping_pong_cond.rb:30:in `<main>'

    Furthermore, it works fine with Ruby 1.9 on Vista.

    As i know there is some change in Ruby threads/Native threads between
    1.8 and 1.9, i suspect this change could be the culprit...

    Any clue?

    Thanks
     
    Eric Jacoboni, Feb 20, 2008
    #1
    1. Advertising

  2. In article <-did-not-set--mail-host-address--so-tickle-me>,
    Eric Jacoboni <> wrote:
    >As i know there is some change in Ruby threads/Native threads between
    >1.8 and 1.9, i suspect this change could be the culprit...


    My memory about 5.x is a bit fuzzy now but can you do an "ldd $(which ruby)"
    please? Check whether you are using libc_r or libpthread. If you can I'd
    suggest moving on 6.3 using libthr (new 1:1 threading library).

    --
    Ollivier ROBERT -=- EEC/RIF/SEU -=-
    Systems Engineering Unit
     
    Ollivier Robert, Feb 20, 2008
    #2
    1. Advertising

  3. Ollivier Robert <> writes:


    > My memory about 5.x is a bit fuzzy now but can you do an "ldd $(which ruby)"
    > please? Check whether you are using libc_r or libpthread. If you can I'd
    > suggest moving on 6.3 using libthr (new 1:1 threading library).


    [mass-cara]:~ % ldd $(which ruby)
    /usr/local/bin/ruby:
    libthr.so.2 => /usr/lib/libthr.so.2 (0x28173000)
    libcrypt.so.3 => /lib/libcrypt.so.3 (0x28185000)
    libm.so.4 => /lib/libm.so.4 (0x2819d000)
    libc.so.6 => /lib/libc.so.6 (0x281b3000)
    [mass-cara]:~ % ldd $(which ruby18)
    /usr/local/bin/ruby18:
    libruby18.so.18 => /usr/local/lib/libruby18.so.18 (0x2807a000)
    libcrypt.so.3 => /lib/libcrypt.so.3 (0x28138000)
    libm.so.4 => /lib/libm.so.4 (0x28150000)
    libpthread.so.2 => /lib/libpthread.so.2 (0x28166000)
    libc.so.6 => /lib/libc.so.6 (0x2818b000)


    The ruby 1.9 was built from scratch using the classic
    "configure/make/make install" idiom.

    The ruby 1.8 is built from FBSD ports.
     
    Eric Jacoboni, Feb 20, 2008
    #3
  4. Ollivier Robert <> writes:


    > My memory about 5.x is a bit fuzzy now but can you do an "ldd $(which ruby)"
    > please? Check whether you are using libc_r or libpthread. If you can I'd
    > suggest moving on 6.3 using libthr (new 1:1 threading library).


    My mistake... My FBSD is a 6.2, not a 5...

    [mass-cara]:~ % ldd $(which ruby)
    /usr/local/bin/ruby:
    libthr.so.2 => /usr/lib/libthr.so.2 (0x28173000)
    libcrypt.so.3 => /lib/libcrypt.so.3 (0x28185000)
    libm.so.4 => /lib/libm.so.4 (0x2819d000)
    libc.so.6 => /lib/libc.so.6 (0x281b3000)
    [mass-cara]:~ % ldd $(which ruby18)
    /usr/local/bin/ruby18:
    libruby18.so.18 => /usr/local/lib/libruby18.so.18 (0x2807a000)
    libcrypt.so.3 => /lib/libcrypt.so.3 (0x28138000)
    libm.so.4 => /lib/libm.so.4 (0x28150000)
    libpthread.so.2 => /lib/libpthread.so.2 (0x28166000)
    libc.so.6 => /lib/libc.so.6 (0x2818b000)


    The ruby 1.9 was built from scratch using the classic
    "configure/make/make install" idiom.

    The ruby 1.8 is built from FBSD ports.
     
    Eric Jacoboni, Feb 20, 2008
    #4
    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. snacktime
    Replies:
    4
    Views:
    890
    Andrew MacIntyre
    Feb 8, 2005
  2. Mike C. Fletcher
    Replies:
    0
    Views:
    266
    Mike C. Fletcher
    Apr 18, 2005
  3. Brian Candler
    Replies:
    5
    Views:
    154
  4. Ralph Smith
    Replies:
    6
    Views:
    199
    Pit Capitain
    Oct 26, 2005
  5. Eric Jacoboni

    Ruby 1.9, threads and FreeBSD 5

    Eric Jacoboni, Feb 20, 2008, in forum: Ruby
    Replies:
    6
    Views:
    138
    MenTaLguY
    Feb 20, 2008
Loading...

Share This Page