On 6/20/06, Francis Cianfrocca <garb...@gmail.com> wrote:
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.
That is not true, it is completely possible to use an OS level
mutex/critical section etc, from inside a "green" Ruby thread. It will
block all Ruby threads which is not very nice, but I do not know of a
better solution.
I used a system mutex (actually a CriticalSection) in both threads --
yes it blocks ruby, but only long enough to read the memory. It would
be better if the Ruby C API provide a thread safe wait for non-native
threads -- but this does work and is completely thread safe even if I
were not doing an atomic operation (for example working off a linked
list).
pth