From: Francis Cianfrocca Date: 2006-06-20T21:14:19+09:00 Subject: Re: C Threads and Ruby ------=_Part_9696_7701601.1150805656730 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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. ------=_Part_9696_7701601.1150805656730--