------art_17560_3437778.1159941064617
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 10/4/06, Serge Kruppa <serge.kruppa / simitel.com> wrote:
>
> Dear All,
>
> I have created a Ruby extension that runs under both Windows (Ruby
> 1.8.4) and Linux (Ruby 1.8.5), using SWIG. The extension is written in
> C and is multi-threaded, thanks to PThreads. Several C functions are
> exported to Ruby to perform various operations.
>
> One of the C functions is a callback notifier whose usage is as
> follows:



You're making some assumptions here which I think are challenging. Whenever
your Ruby code calls native code, Ruby will block until the native call
returns. If the native call makes calls back into Ruby, you're generally
safe. But if you spin native threads that call Ruby code (as you suggest
here) then you will have no way to completely synchronize the Ruby code that
is now running on multiple native threads.

There have been several discussions on this list about how to send events
back and forth between Ruby and native code running on native threads. The
ideas which seem to work generally involve sending messages on socketpairs
or pipes. A look through the archives may help you.

If you have the freedom to re-architect your application, look at the
EventMachine library. It was designed to enable applications like yours to
be implemented without threads.

------art_17560_3437778.1159941064617--