Bill Kelly
3/1/2006 5:20:00 AM
From: "zdennis" zdennis@mktec.com
>
> Bill Kelly wrote:
>>
>> (*) Sleeping in C++ for an event from a Ruby thread: The C++ thread
>> sleeps on a boost::condition variable. The Ruby thread invokes a C
>> extension method which notify()'s the condition variable. Simple
>> enough in this direction.
>>
>
> Can't you do this the other way around as well.... write C/C++ extension
> for ruby which stores reference to ruby thread, and call it from c++ code
> which would wake your ruby thread?
All ruby threads run on a single OS thread, and the ruby
interpreter isn't generally reentrant, as I understand it.
So I don't know how to put one ruby thread to sleep on something
like a boost::condition variable without sleeping the whole OS
thread ruby runs on, thus blocking all ruby threads.
And I also don't know if I can call straight into ruby's eval.c
from a non-ruby OS thread, to try to fiddle with the ruby threads
and the ruby scheduler to wake my ruby thread up - due to the
ruby interpreter not being reentrant. (Without hacking the ruby
source code, at any rate.) Although if anyone knows to the
contrary, that an external OS thread can safely wake up a
ruby thread that'd be great.
I may end up trying the UDP approach. It's got to be better
than my initial make-it-work implementation, where my ruby
threads sleep for 1/10 second and check a queue.
But if anybody knows another way .... ? :)
Regards,
Bill