Subject: [ruby-ffi] Re: native thread callback woes |
From: Wayne Meissner |
Date: 3/21/10 6:13 AM |
To: ruby-ffi |
I *think* this should work now. Whenever a callback to ruby from a non-ruby native thread is encountered, the native thread is paused, the callback is despatched on a new ruby thread, and the the result of the callback is returned to the native thread. Its 1.9 only, and you really want to restrict your gem to running on CRuby 1.9 or JRuby (both 1.8 and 1.9 mode will work). You will also need to mark any function that waits in native code as blocking. I'm not sure what the best API for this is, but I implemented a quick&dirty hack for 0.6.4 that won't break backward compatibility with older versions of Ruby-FFI or JRuby. To mark a method as blocking, you simply set the @blocking ivar before each attach_function call e.g. @blocking = true attach_function :al_wait_for_event, [:pointer, :pointer], :void @blocking is non-sticky - i.e. it gets reset after every attach_function, and is assumed to be non-true by default. On Mar 20, 3:36 am, Shawn Anderson <shaw...@gmail.com> wrote:
https://gist.github.com/95d3ccc14fd8fdc1febf Allegro spins off a new native thread (os x only) and calls the callback from that native thread. Apparently os x needs the main thread for its event stuff... Is there anyway to let this new non-ruby native thread call back into ruby code? http://github.com/shawn42/ffi-allegrohttp://alleg.sourceforge.net/ /ShawnI'm trying to get allegro-ffi to work with the latest 4.9 branch of allegro in SVN. Allegro has recently changed to run everything in a native callback. ie.. ... setup code ... al_run_main argc, argv, &method(:run) puts "this code will never be called" running this in ruby 1.9.1 I see the error: examples/simple_window.rb:13: [BUG] object allocation during garbage collection phase ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0] full trace here:
To unsubscribe from this group, send email to ruby-ffi+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.