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.