Forum: Ruby Blocking read blocks all threads on Windows?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2007-07-26 14:31
(Received via mailing list)
If I run this on Linux (Ruby 1.8.6), it times out as I'd expect:

require 'timeout'
r, w = IO.pipe
Timeout::timeout(2) { r.getc }

But if I run it on Windows, it blocks forever. Similarly the following
code locks up on Windows:

r, w = IO.pipe { r.getc }

It appears that if one thread blocks attempting to read, all Ruby
threads block.

Is there any way round this?

What I'm really trying to do is write an extension where I want to
block a Ruby thread (leaving others running), and then unblock it when
something happens in a different native thread. The method I'm trying
to use at the moment is to call IO.pipe, have the Ruby thread call
getc on it and the native thread use a native write() call on the
fileno of the write side of the pipe. This works fine on Linux, and
works on Windows - but ends up blocking all Ruby threads because of
the issue above. Is there a better solution?


This topic is locked and can not be replied to.