Blocking read blocks all threads on Windows?

A

AlanMStokes

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
Thread.new { 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?

Thanks,

Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top