#15 Time.delay does not work nicely with Ruby threads.

open
nobody
None
5
2005-01-13
2005-01-13
robert-s
No

Timer.delay seems to stop calls to the Ruby thread
scheduler.

This example demonstrates the problem, running on Linux
Fedora Core 3 with RUDL 0.8 and ruby 1.8.2 (2004-12-25)
[i686-linux]:

require 'RUDL'

loops = 0
tstart = RUDL::Timer.ticks

$stdout.sync = true
$stderr.sync = true
command = loops
Thread.new do
loop do
command = loops
puts command
end
end

old_command = loops - 1

while true
# $stderr.puts command
if command != old_command
$stderr.puts command
old_command = command
end
RUDL::Timer.delay 10
exit if command >= 100
loops += 1
end

If the commented line is uncommented then the code
works as expected. I presume because the output causes
the Ruby thread switcher to be called.

Discussion

  • Renne Nissinen
    Renne Nissinen
    2005-03-02

    Logged In: YES
    user_id=870555

    I have also encountered some problems with threads and
    Timer.delay... Using the standard sleep() seems to work better.