# Blocking read blocks all threads on Windows?

**URL:** <https://www.ruby-forum.com/t/blocking-read-blocks-all-threads-on-windows/110446>\
**Category:** Ruby\
**Created:** [July 26, 2007, 12:31pm UTC](https://www.ruby-forum.com/t/blocking-read-blocks-all-threads-on-windows/110446 "2007-07-26T12:31:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 26, 2007, 12:31pm UTC](https://www.ruby-forum.com/t/blocking-read-blocks-all-threads-on-windows/110446/1 "2007-07-26T12:31:24Z")

</div>

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
