Ruby 1.9, threads and FreeBSD 5

E

Eric Jacoboni

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
 
O

Ollivier Robert

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).
 
E

Eric Jacoboni

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.
 
E

Eric Jacoboni

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top