From: Francis Cianfrocca [mailto:garbagecat10 / gmail.com]
Sent: Friday, June 30, 2006 5:29 AM
> On 6/29/06, Victor 'Zverok' Shepelev <vshepelev / imho.com.ua> wrote:
> >
> > Hi all.
> > I've tried the simple code:
> >
> > Thread.new{ runMessageCycle}
> > puts 'here'
> >
> > where runMessageCycle is a simple C extension method with Win32 message
> > cycle:
> >
> > static VALUE run(VALUE _self)
> > {
> >         MSG msg;
> >         while (::GetMessage(&msg, NULL, 0, 0))
> >         {
> >                 ::TranslateMessage(&msg);
> >                 ::DispatchMessage(&msg);
> >         }
> >
> >         return _self;
> > }
> >
> > I'm very surprised that Thread.new don't returns ("here" will be never
> > printed).
> > What is silly with my code?
> My guess would be that runMessageCycle never returns (until the while loop
> breaks, anyway) so Ruby never gets a chance to execute any more code. 

Yes, It never returns. But I've thought its not a problem, because in the
code:
Thread.new{ sleep(10000) }
puts 'here'
sleep(10000) also virtually never returns, but code works as expected
(prints 'here' and exits).

> The C
> code in the extension doesn't know anything about Ruby's thread scheduler.
> I
> haven't tried this, but what if you called rb_thread_select with an empty
> descriptor set on each pass through the while loop?

Hmmm... Ok, I'll try. But I think there must be more general solution for
threading C extension. No?

V.