From: reynhout@... Date: 2009-07-14T01:48:40+09:00 Subject: C ext / threading / callback issue, ruby-1.9.1p129 Hi, I've never written a C extension for Ruby before, and I'm struggling with some demo code which uses C and/or Ruby pthreads, and a C or Ruby callback (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 works... 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 figured that out obviously, but I have a feeling that the second problem (threads 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 Apache 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 :).. http://github.com/reynhout/callme/ Thank you! Andrew -- reynhout@quesera.com