From: Eric Schwartz Date: 2003-02-25T11:51:30+09:00 Subject: C Extension not exiting properly? This is puzzling me mightily. I have written a C extension to Ruby to allow it to interact with STAF. All of a sudden, it's starting to cause my Ruby programs that use it to hang on exit. The truly odd thing is that it will sometimes work once or twice, then stop. Here's a simple CGI program that will exhibit the behaviour: #!/usr/bin/ruby -w $:.push('/home/emschwar/src/lsotest/cgi-bin') require 'cgi' require 'staf/STAFHandle' cgi = CGI.new('html4'); cgi.out { cgi.html { cgi.head { cgi.title { "Testing" } }+ cgi.body { cgi.p {"It's only a test"}} } } Notice that it does not actually use the STAFHandle class; it just loads it. This is apparently sufficient. I've posted the contents of the library (it's not large, but 178 lines is too large for USENET) to http://people.debian.org/~emschwar/libstaf-ruby.tar.gz if you care to peruse it. Here's what happens when I run the above program as a CGI emschwar 6201 4319 1 19:25 ? 00:00:00 /usr/bin/ruby -w testing emschwar 6205 6201 0 19:25 ? 00:00:00 [testing] (process 4319 is apache). When I run it on the command-line, it runs correctly for two or three times, and then hangs in exactly the same situation as above. No output is produced in that case. Interestingly, I've even ifdef'd out Init_STAFHandle() in STAFHandle.c, and it *still* does this. I confess to severe frustration here. Any clues would be most welcome. Another data point: attaching to the hung ruby process with gdb gives me a stack trace that indicates ruby is trying to exit, and somehow this extension is inhibiting it: #0 0x40134ae2 in sigsuspend () from /lib/libc.so.6 #1 0x40362f35 in __pthread_wait_for_restart_signal () from /lib/libpthread.so.0 #2 0x40362be2 in pthread_onexit_process () from /lib/libpthread.so.0 #3 0x40136884 in exit () from /lib/libc.so.6 #4 0x4003c7d9 in ruby_stop () from /usr/lib/libruby.so.1.6 #5 0x4003c8e6 in ruby_run () from /usr/lib/libruby.so.1.6 #6 0x080485b4 in main () #7 0x40123a51 in __libc_start_main () from /lib/libc.so.6 I'm not (explicitly, anyhow) using pthreads, so I can only assume that ruby is somehow doing this on my behalf. -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton.