C Threads and Ruby

Simon:

Well.. ??? yes of course, if you block the one and only thread

on an IO operation that never returns your program will block
forever. This should be true for linux also, right?
<<<

It has nothing to do with threads. I only took a quick look at the Ruby
source code, but I suspect there is a bug in the Windows implementation.
Remember, I got the same result as you did even when I took out your thread.
And it did work fine on both Linux and OSX. Ruby's green threads
implementation does not block the whole process when waiting for an I/O
because its scheduler interacts with multiplexed I/O.

native Win32 means calling 'CreatePipe' instead of '_pipe' ?

do you have code for a platform independent implementation?
(using #ifdef)
<<<

Windows does have Unix-like calls for doing this. (They're wrappers over
Win32 APIs.) I forget which one I've used but I think it was pipe().
Also, there may be something in Daniel Berger's win32 library that may help
you.

···

On 6/21/06, Kroeger, Simon (ext) <simon.kroeger.ext@siemens.com> wrote:

> From: Francis Cianfrocca [mailto:garbagecat10@gmail.com]
> Sent: Wednesday, June 21, 2006 12:26 AM

> > The problem isn't that rd.gets waits forever - i didn't described my
> > problem well enough obviously. The problem is: i get 4 foo!s not one
> > more. Not only the main thread blocks at the gets but all other ruby
> > threads do also block. This defeats the whole purpose of
> using a pipe
> > in the first place.
>
> Yes, this does fail on Windows as written (works fine on
> Unix), but it has
> nothing to do with threads. Take out the thread altogether
> and it will still
> block forever.

Well.. ??? yes of course, if you block the one and only thread
on an IO operation that never returns your program will block
forever. This should be true for linux also, right?

So the problem is that all threads block because of this IO
operation, how could that be unrelated to threads?

> Try writing an extension in C and create your descriptors in
> native Win32
> code. Those will definitely work with Ruby on both Windows
> and Unix (I've
> done it). You may have to create two pairs because they will
> be half-duplex
> on Windows.

native Win32 means calling 'CreatePipe' instead of '_pipe' ?
do you have code for a platform independent implementation?
(using #ifdef)

for the record: ruby 1.9.0 (2006-04-15) [i386-mswin32] seems
to have a fix for that problem.

cheers

Simon