From: Matthijs Langenberg Date: 2008-05-28T23:36:44+09:00 Subject: Re: Writing event hooks called from C extensions On #ruby-lang, drbrain explained to me that I should run my event loop handler inside a seperate thread. I understand why that should be, but I've no clue how to launch a seperate thread from a C extension and communicatie back to the Ruby thread. Can anybody give me a head start? - Matt On Tue, May 27, 2008 at 9:44 PM, Matthijs Langenberg wrote: > Just for educational purposes, I'm trying to write a Ruby-C extension > that allows me to hook into Carbon's event handler. So I can handle > mouse clicks in Ruby. > Mouse clicks (like all events) happen asynchronously, meaning that > something needs to be running inside a seperate thread, but I find it > hard to grasp how this all works out. > > I've already figured out the following code: http://pastie.org/204180. > This allows me to include the 'MouseEvents' module somewhere and call > 'hook'. This works, and prints 'click' to my console, but it blocks > ruby. > > Would it be possible to start a seperate Thread from inside the C > extension, which calls into ruby (or executes a block) asynchronously? > > - Matt > >