Blocking read blocks all threads on Windows?


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?