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.

Hi,

···

In message “C Extension not exiting properly?” on 03/02/25, Eric Schwartz eric.schwartz@hp.com writes:

I’m not (explicitly, anyhow) using pthreads, so I can only assume that
ruby is somehow doing this on my behalf.

Ruby never works well with pthread. If you’re not using ptherad,
something is wrong with your installation. Give us information about
your platform, how you compiled Ruby, etc.

						matz.

Hi,

···

At Tue, 25 Feb 2003 15:42:19 +0900, Yukihiro Matsumoto wrote:

I’m not (explicitly, anyhow) using pthreads, so I can only assume that
ruby is somehow doing this on my behalf.

Ruby never works well with pthread. If you’re not using ptherad,
something is wrong with your installation. Give us information about
your platform, how you compiled Ruby, etc.

Or libSTAF may use pthread. Eric, you should check the library
with ldd.


Nobu Nakada

matz@ruby-lang.org (Yukihiro Matsumoto) writes:

Ruby never works well with pthread. If you’re not using ptherad,
something is wrong with your installation. Give us information about
your platform, how you compiled Ruby, etc.

Okay, turns out nobu.nokada@softhome.net was right; libSTAF.so is
linking in libpthread.so. I apologize for assuming it was Ruby doing
it. The ruby I’m running is 1.6.8 from debian unstable:

ii ruby 1.6.8-3 An interpreter of object-oriented
ii ruby-dev 1.6.8-3 Header files for compiling extension

The platform is i386 linux running 2.4.20. STAF is version 2.4.2,
from http://staf.sourceforge.net/

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.