I’ve never written a C extension for Ruby before, and I’m struggling
some demo code which uses C and/or Ruby pthreads, and a C or Ruby
(address passed as an arg into the C lib).
There’s a watcher thread (in C) that waits for an event (the creation of
a file), then triggers whichever callback is specified.
Triggering the Ruby callback causes MRI to crash. The C callback
but when it completes, all Ruby threads appear to suspend (control is
never returned to Ruby / the threads are never rejoined?)
I’m guessing that the MRI crash is a dereferencing bug?? I haven’t
that out obviously, but I have a feeling that the second problem
never rejoin?) will show up after the crash is resolved.
I put the code up on github: http://github.com/reynhout/callme/ . There
is a bunch more description there, too.
There are two versions, C_ext (described above), and FFI_lib which uses
ruby-ffi to achieve the same goals … but is also failing similarly.
I worked on the FFI_lib one first, then backed down to a straight C ext
trying to simplify it and make the bugs easier to find.
I’m pretty sure that if I can get the C_ext version working, the FFI_lib
one will fall into place. The ultimate goal is a Ruby library for
ZooKeeper. The rest of the code is going great, but many ZK functions
depend on this sort of mechanism…
I hope the bugs are obvious to anyone who has written a C ext before.
I’d greatly appreciate any ideas or pointers (no pun intended :)…