21 messages in org.ruby-lang.ruby-talkRe: C Threads and Ruby
FromSent OnAttachments
Kroeger, Simon (ext)Jun 20, 2006 3:27 am 
Patrick HurleyJun 20, 2006 4:28 am 
Kroeger, Simon (ext)Jun 20, 2006 4:59 am 
Francis CianfroccaJun 20, 2006 5:13 am 
Patrick HurleyJun 20, 2006 9:39 am 
Paul BrannanJun 20, 2006 11:33 am 
Patrick HurleyJun 20, 2006 1:16 pm 
Francis CianfroccaJun 20, 2006 1:17 pm 
Francis CianfroccaJun 20, 2006 1:19 pm 
Simon KrögerJun 20, 2006 2:29 pm 
Joel VanderWerfJun 20, 2006 2:35 pm 
Francis CianfroccaJun 20, 2006 2:39 pm 
Bill KellyJun 20, 2006 2:42 pm 
Simon KrögerJun 20, 2006 2:49 pm 
Francis CianfroccaJun 20, 2006 3:26 pm 
Francis CianfroccaJun 20, 2006 3:34 pm 
Bill KellyJun 20, 2006 4:08 pm 
Francis CianfroccaJun 20, 2006 5:07 pm 
Kroeger, Simon (ext)Jun 21, 2006 2:53 am 
Francis CianfroccaJun 21, 2006 3:15 am 
Paul BrannanJun 22, 2006 8:21 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: C Threads and RubyActions...
From:Patrick Hurley (phur@gmail.com)
Date:Jun 20, 2006 4:28:09 am
List:org.ruby-lang.ruby-talk

On 6/20/06, Kroeger, Simon (ext) <simo@siemens.com> wrote:

Hi,

i know the ruby interpreter isn't thread safe and it's not a good idea to call rb_* functions from more than one thread.

Nevertheless, is there a way to signal the interpreter that i would like him to call one of my functions in a c extension? (from another thread)

The only way i figured out so far would be to create a pipe, let a ruby thread sleep on the fd and put a byte in the queue from c the wake the thread. (good, bad, ugly?)

cheers

It depends what you are trying to do. I just worked up a patch to win32-service, that does this by creating a ruby thread in the C extension that polls against a simple integer guarded by a mutex -- when an event occurs it is signaled there and the correct call back is spun off in yet another ruby thread. I was worried this would be "expensive", but the rb_thread_polling method, worked like a charm.

This idea could be easily extended to allow for an event queue that was filled by a native C thread and processed by a ruby thread. Note that calling any rb_XXXX from anything other than the "ruby thread" is a really bad idea.

pth