Ruby dream in a loop in a stream

I have the same problem posted here a year ago: Ruby Loop error in thread

Here's the code (almost the same as in the topic above)

 class NewObject
    def my_funk
        t = Thread.new {
            until false do
                puts sleep 15 # sleeps way too much
            end
        }
        t.join
  end
end

if __FILE__ == $0
    s = NewObject.new()
    s.my_funk
end

And here is the conclusion:

15
42
36
38
33
45
42
33
32
40

Basically the code prints the actual number of seconds. Does anyone know what is going on here and how to fix it?

I am running Windows 7 and Ruby 1.8.7

+3
source share
1 answer

If I am not mistaken, the dream is realized using its own system call and probably interferes with the ruby ​​green flows controlled by the virtual machine. This also explains why JRuby and 1.9 do not suffer from the same problem ....

0

Source: https://habr.com/ru/post/1769998/


All Articles