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:inblock in ’
from ping_pong_cond.rb:30:in each' from ping_pong_cond.rb:30:in’
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
In article
removed_email_address@domain.invalid.i-did-not-set--mail-host-address--so-tickle-me,
Eric J. [email protected] 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 R. [email protected] 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.