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:Francis Cianfrocca (garb@gmail.com)
Date:Jun 20, 2006 5:13:56 am
List:org.ruby-lang.ruby-talk

Patrick: given your proposal for an event queue filled by native threads in C and consumed by a Ruby thread, notice that there is no mutex that works between native threads and Ruby threads. Your example of "signalling" by changing the value of an integer probably works because on an Intel chip (you said you did this on Windows), it only takes one memory-bus cycle to change the value of a 32-bit integer, so you can get away without a mutex. I doubt this would work with a more complex data structure.

Simon: the pipe idea will work (I used it in an early version of eventmachine), but there are a few gotchas. First, the IO objects (pipe and socketpair, can't remember exactly which one I used) are full-duplex on Unix but half-duplex on Windows. Next, you still won't be able to synchronize between Ruby and native threads. I infer from your description that you want Ruby to sleep while your native thread(s) run, and then to call a native function. Presumably this will happen while other native threads continue to run.

I thought about writing an extension that would allow Ruby code to access the native mutexes and other synchronization objects, and I think one of the core guys has worked on this. It would be a bit tricky because condvars don't work perfectly on Windows, but you could wrap the native Windows objects if you really had to.