M
Michael Malone
Hi All,
Here's a tricky one for you:
require 'thread'
THREADS = 10
WASTE = 10000
pid = fork() do
queue = Queue.new
THREADS.times do |i|
queue << Thread.new do
# wasting actual cpu time, rather than sleeping
Thread.current[:index] = i
n = rand(WASTE)
Thread.current[:n] = n
d = 1.0 + 1/n.to_f
e = 1.0
n.times { e = e * d }
end
end
THREADS.times do
th = queue.pop
puts "Joining thread #{th[:index]}, n=#{th[:n]}"
th.join()
end
end
Process.wait(pid)
If I run this using ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] I
get the output I would expect:
Joining thread 0, n=8767
Joining thread 1, n=2401
Joining thread 2, n=514
Joining thread 3, n=5227
Joining thread 4, n=658
Joining thread 5, n=8618
Joining thread 6, n=2356
Joining thread 7, n=7431
Joining thread 8, n=8426
Joining thread 9, n=588
If I run this using either ruby 1.9.1p0 (2009-01-30 revision 21907)
[i686-linux] or ruby 1.9.2dev (2009-03-05 trunk 22769) [i686-linux] I
get results I would not expect:
Joining thread , n=
Joining thread 1, n=1131
Joining thread 2, n=8233
Joining thread 3, n=8696
Joining thread 4, n=7684
Joining thread 5, n=286
Joining thread 6, n=6618
Joining thread 7, n=2814
Joining thread 8, n=5862
Joining thread 9, n=6307
My best guess is that something similar to the fix for this bug
http://redmine.ruby-lang.org/issues/show/657 is happening, but elsewhere
in the code. Does anyone have any ideas?
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
=======================================================================
Here's a tricky one for you:
require 'thread'
THREADS = 10
WASTE = 10000
pid = fork() do
queue = Queue.new
THREADS.times do |i|
queue << Thread.new do
# wasting actual cpu time, rather than sleeping
Thread.current[:index] = i
n = rand(WASTE)
Thread.current[:n] = n
d = 1.0 + 1/n.to_f
e = 1.0
n.times { e = e * d }
end
end
THREADS.times do
th = queue.pop
puts "Joining thread #{th[:index]}, n=#{th[:n]}"
th.join()
end
end
Process.wait(pid)
If I run this using ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] I
get the output I would expect:
Joining thread 0, n=8767
Joining thread 1, n=2401
Joining thread 2, n=514
Joining thread 3, n=5227
Joining thread 4, n=658
Joining thread 5, n=8618
Joining thread 6, n=2356
Joining thread 7, n=7431
Joining thread 8, n=8426
Joining thread 9, n=588
If I run this using either ruby 1.9.1p0 (2009-01-30 revision 21907)
[i686-linux] or ruby 1.9.2dev (2009-03-05 trunk 22769) [i686-linux] I
get results I would not expect:
Joining thread , n=
Joining thread 1, n=1131
Joining thread 2, n=8233
Joining thread 3, n=8696
Joining thread 4, n=7684
Joining thread 5, n=286
Joining thread 6, n=6618
Joining thread 7, n=2814
Joining thread 8, n=5862
Joining thread 9, n=6307
My best guess is that something similar to the fix for this bug
http://redmine.ruby-lang.org/issues/show/657 is happening, but elsewhere
in the code. Does anyone have any ideas?
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
=======================================================================