Ruby not exiting when developing extension

I’ve been working on ruby bindings to libxosd2 for a couple days. It’s
all going quite well, and the library is in a state that I’m ready to
release it, except for one thing.
Sometimes (and it seems fairly random to me) the ruby process that’s
requiring the library just refuses to exit. I can’t ctrl-C it, all I can
do is kill it.
I’ve written a small test script that seems to cause the problem about as
often as I can get it to, and I’m hoping someone with a bit more
experience with writing extensions can take a look and help me out. I’ve
so far experienced the problems on ruby 1.6.8 and 1.8.0, both on Linux on
i386.
I can ctrl-Z the process, and doing a ‘ps’, I see this:
PID TTY TIME CMD
16727 pts/16 00:00:00 bash
17321 pts/16 00:00:00 ruby
17322 pts/16 00:00:00 ruby
17359 pts/16 00:00:00 ps

If anyone wants to help me out, you’ll need libxosd2, and the equivalent
development package installed, as well as libxosd2-ruby from cvs.

Here’s the cvs info for libxosd2-ruby:

cvs -d:pserver:anonymous@rubyforge.org:/var/cvs/libxosd-ruby login
(password is blank)

cvs -z3 -d:pserver:anonymous@rubyforge.org:/var/cvs/libxosd-ruby co libxosd2-ruby

The these three commands:

  1. ruby extconf.rb
  2. make
  3. ruby break1.rb

Executing the 3rd one repeatedly should eventually cause it to not exit,
and not respond to ctrl-C.

Derek Lewis

···

===================================================================
Java Web-Application Developer

  Email    : email@lewisd.com
  Cellular : 604.312.2846
  Website  : http://www.lewisd.com

“If you’ve got a 5000-line JSP page that has “all in one” support
for three input forms and four follow-up screens, all controlled
by “if” statements in scriptlets, well … please don’t show it
to me :-). Its almost dinner time, and I don’t want to lose my
appetite :-).”
- Craig R. McClanahan

I've written a small test script that seems to cause the problem about as
often as I can get it to, and I'm hoping someone with a bit more
experience with writing extensions can take a look and help me out.

It use pthread.

Now don't expect it to work actually with ruby thread. If you want to use
xosd_wait_until_no_display() emulate it like described in the manual page.

Perhaps you can also use the CVS version of ruby, compiled with
--enable-pthread

Guy Decoux

I’ve been working on ruby bindings to libxosd2 for a couple days. It’s
all going quite well, and the library is in a state that I’m ready to
release it, except for one thing.

Looks like I should have posted earlier. A few weeks ago I wrote some
libxosd bindings. I was waiting to release it, though, because I was
having the same problem you were.

Sometimes (and it seems fairly random to me) the ruby process that’s
requiring the library just refuses to exit. I can’t ctrl-C it, all I can
do is kill it.

I noticed the problem when trying to set an invalid font. Sometimes it
would just get an error, as it is supposed to, but sometimes the program
would sit there and refuse to exit.

I haven’t been working on it lately, but if you find a solution, I’d
definitely like to know what it is.

···

On Thu, Dec 04, 2003 at 10:05:11AM +0900, Derek Lewis wrote:


Zachary P. Landau kapheine@hypa.net
GPG: gpg --recv-key 0x24E5AD99 | http://kapheine.hypa.net/kapheine.asc

Hmm, pthread, I see. Is there some way I can make them work together
nicely? Even when I never call wait_until_no_display, ruby still
doesn’t exit properly. I’ve tried using at_exit to add a handler that
cleans-up the xosd library properly, which should clean up any threads
it’s using, but that doesn’t seem to help either.

I’ve tried running my simple test (that usually fails) it in gdb, but that
seems to make the problem disapear. I’ve run my larger application that
uses xosd in gdb, and when it locks during exit, this is the backtrace:
#0 0x402ed354 in __pthread_sigsuspend () from /lib/libpthread.so.0
#1 0xbffff6f8 in ?? ()
#2 0x402ed118 in __pthread_wait_for_restart_signal ()
from /lib/libpthread.so.0
#3 0x402ecd29 in pthread_onexit_process () from /lib/libpthread.so.0
#4 0x40139a92 in exit () from /lib/libc.so.6
#5 0x4003b7d9 in ruby_stop () from /usr/lib/libruby.so.1.6
#6 0x4003b8e6 in ruby_run () from /usr/lib/libruby.so.1.6
#7 0x080485b4 in main ()
#8 0x40123e3e in __libc_start_main () from /lib/libc.so.6

Definitely related to phread. Any C/pthread gurus out there know what
this means? If there’s some way I can properly shutdown the pthreads…

···

On Thu, 4 Dec 2003, ts wrote:

I’ve written a small test script that seems to cause the problem about as
often as I can get it to, and I’m hoping someone with a bit more
experience with writing extensions can take a look and help me out.

It use pthread.

Now don’t expect it to work actually with ruby thread. If you want to use
xosd_wait_until_no_display() emulate it like described in the manual page.

Perhaps you can also use the CVS version of ruby, compiled with
–enable-pthread

Guy Decoux

Derek Lewis

===================================================================
Java Web-Application Developer

  Email    : email@lewisd.com
  Cellular : 604.312.2846
  Website  : http://www.lewisd.com

“If you’ve got a 5000-line JSP page that has “all in one” support
for three input forms and four follow-up screens, all controlled
by “if” statements in scriptlets, well … please don’t show it
to me :-). Its almost dinner time, and I don’t want to lose my
appetite :-).”
- Craig R. McClanahan

Hmm, pthread, I see. Is there some way I can make them work together
nicely? Even when I never call wait_until_no_display, ruby still
doesn't exit properly.

Like I've said try with the CVS version of ruby and compile ruby with
--enable-pthread

It worked for me : I've stopped the program (after a long time) only
because you use very weird colour (green or yellow ???) for the
message :-(((

Guy Decoux

Heh. That green is acctually the xosd library’s default. It’s supposed
to resemble the green volume/balance bars on a TV screen. :wink:

Anyways, about --enable-pthread, I could try it, as an exercise, but
seeing as I’d like to distribute this library, I would rather not force
people to recompile ruby to use it. :slight_smile: So, if there’s any possible way of
getting pthread to play nicely with the standard ruby distribution, I’d
like to try that.

···

On Fri, 5 Dec 2003, ts wrote:

Hmm, pthread, I see. Is there some way I can make them work together
nicely? Even when I never call wait_until_no_display, ruby still
doesn’t exit properly.

Like I’ve said try with the CVS version of ruby and compile ruby with
–enable-pthread

It worked for me : I’ve stopped the program (after a long time) only
because you use very weird colour (green or yellow ???) for the
message :-(((

Guy Decoux

Derek Lewis

===================================================================
Java Web-Application Developer

  Email    : email@lewisd.com
  Cellular : 604.312.2846
  Website  : http://www.lewisd.com

“If you’ve got a 5000-line JSP page that has “all in one” support
for three input forms and four follow-up screens, all controlled
by “if” statements in scriptlets, well … please don’t show it
to me :-). Its almost dinner time, and I don’t want to lose my
appetite :-).”
- Craig R. McClanahan

Can I tell from something in rbconfig.rb wether or not ruby was compiled
with --enable-pthread?

I’ve found a (ugly) workaround for the problem. In my rxosd.rb I have:

at_exit {
exit!
}

It at least ensures that ruby exits.

What I would like to do is check if it was compiles with pthread, and only
‘exit!’ if it wasn’t.

···

On Fri, 5 Dec 2003, ts wrote:

Hmm, pthread, I see. Is there some way I can make them work together
nicely? Even when I never call wait_until_no_display, ruby still
doesn’t exit properly.

Like I’ve said try with the CVS version of ruby and compile ruby with
–enable-pthread

It worked for me : I’ve stopped the program (after a long time) only
because you use very weird colour (green or yellow ???) for the
message :-(((

Guy Decoux

Derek Lewis

===================================================================
Java Web-Application Developer

  Email    : email@lewisd.com
  Cellular : 604.312.2846
  Website  : http://www.lewisd.com

“If you’ve got a 5000-line JSP page that has “all in one” support
for three input forms and four follow-up screens, all controlled
by “if” statements in scriptlets, well … please don’t show it
to me :-). Its almost dinner time, and I don’t want to lose my
appetite :-).”
- Craig R. McClanahan

Anyways, about --enable-pthread, I could try it, as an exercise, but
seeing as I'd like to distribute this library, I would rather not force
people to recompile ruby to use it. :slight_smile: So, if there's any possible way of
getting pthread to play nicely with the standard ruby distribution, I'd
like to try that.

It don't exist a possibility to disable pthread for libxosd2 ?

Guy Decoux

Can I tell from something in rbconfig.rb wether or not ruby was compiled
with --enable-pthread?

well, you have

svg% grep pthread rbconfig.rb
  CONFIG["LIBS"] = "-lpthread -ldl -lcrypt -lm "
  CONFIG["configure_args"] = "'--enable-pthread' '--prefix=/home/ts/local/rp'"
svg%

Guy Decoux

I thought about that too… but that would mean recompiling the library
in order to use it with ruby. That seems like a lot of hastle to ask your
average user to go through to get some simple feature working.
I think there’s great potential in making a tool like xosd available in
a language like ruby, but it won’t happen if people have to recompile
things just to use it.

···

On Fri, 5 Dec 2003, ts wrote:

Anyways, about --enable-pthread, I could try it, as an exercise, but
seeing as I’d like to distribute this library, I would rather not force
people to recompile ruby to use it. :slight_smile: So, if there’s any possible way of
getting pthread to play nicely with the standard ruby distribution, I’d
like to try that.

It don’t exist a possibility to disable pthread for libxosd2 ?

Guy Decoux

Derek Lewis

===================================================================
Java Web-Application Developer

  Email    : email@lewisd.com
  Cellular : 604.312.2846
  Website  : http://www.lewisd.com

“If you’ve got a 5000-line JSP page that has “all in one” support
for three input forms and four follow-up screens, all controlled
by “if” statements in scriptlets, well … please don’t show it
to me :-). Its almost dinner time, and I don’t want to lose my
appetite :-).”
- Craig R. McClanahan

Thanks, “LIBS” looks like what I need.

···

On Tue, 9 Dec 2003, ts wrote:

Can I tell from something in rbconfig.rb wether or not ruby was compiled
with --enable-pthread?

well, you have

svg% grep pthread rbconfig.rb
CONFIG[“LIBS”] = "-lpthread -ldl -lcrypt -lm "
CONFIG[“configure_args”] = “‘–enable-pthread’ ‘–prefix=/home/ts/local/rp’”
svg%

Guy Decoux

Derek Lewis

===================================================================
Java Web-Application Developer

  Email    : email@lewisd.com
  Cellular : 604.312.2846
  Website  : http://www.lewisd.com

“If you’ve got a 5000-line JSP page that has “all in one” support
for three input forms and four follow-up screens, all controlled
by “if” statements in scriptlets, well … please don’t show it
to me :-). Its almost dinner time, and I don’t want to lose my
appetite :-).”
- Craig R. McClanahan