Subject:
Re: [ruby-ffi] callback from native thread
From:
Chuck Remes
Date:
12/19/11 5:55 PM
To:
ruby-ffi@googlegroups.com

On Dec 19, 2011, at 11:32 AM, JackNorris wrote:

> I am looking to write an asynchronous ICMP/Ping library to use with
> Ruby + FFI.
> 
> I've not really started writing anything yet I am just curious if FFI
> can handle callbacks from threads that were not created by Ruby. My
> plan is to create a new thread running a libevent loop and call back
> to Ruby when an event occurs (ie a ping response). This leaves the
> ruby thread open to control libevent.
> 
> It would appreciated if anyone could advise me on this, specifically
> if calling back in such a way will work.
> Maybe I am just going about the whole thing the wrong way! :-)

I would highly suggest thinking of a different mechanism for this. It's unlikely something like this would ever be supported across all Ruby runtimes, particularly those that have already removed their GIL.

Why not have that libevent loop just push the event onto a queue that Ruby can see?

cr