Emil Ong wrote:

> Hi,
>
> On Fri, 6 Jul 2001, Wesley James Landaker wrote:
>
> > Here what you can do:
> >
> > Initialize the library you're using.
> >
> > Install a dummy signal handler that does nothing, but SAVE the function
> > pointer that returns from the signal() function. That is the OLD signal
> > handler.
> >
> > Run ruby_init();
> >
> > Reinstall the signal handler that you saved from the return of the signal()
> > call when you installed your dummy handler.
>
> First, I'd like to say that this is a brilliant solution and I really like
> it.  Unfortunately, I'm still running into a problem.  You see, I writing
> a parallel program and I'm running into a race condition.  Sometimes, some
> of the programs are sending SIGUSR1 to each other between the time when
> Ruby sets its handler and when I restore the other library's handler
> (!).  I can solve this by using some synchronization, but this of course
> slows things down.  I'm happy with it now, but I could be happier if Ruby
> never set the signal handlers in the first place.

(This doesn't solve the synchronization problem, but I thought I'd mention this:
...)

BTW, you can also do the same sort of thing, except actually still use ruby's
signal handlers. You'd basically do the following pseudo-code (where let's
assume sighandler_t is a signal handler function pointer):

sighandler_t otherAPIhandler;
sighandler_t rubyhandler;

sighandler_t myhandler() {
   otherAPIhandler();
   rubyhandler();
}

void setupstuff() {
  init_other_API();
  otherAPIhandler = signal(SIGUSR1, myhandler);
  ruby_init();
  rubyhandler = signal(SIGUSR1, myhandler);
}

Then when the signal is triggered, it will call YOUR handler, which as you can
see above, could just call the other API's handler, and the ruby handler
sequentially.

Of course, I haven't actually TRIED this, and I'm not sure what ruby is doing in
their handler, so maybe this would have problems, but it doesn't seem like it.
=)


>
> Anyway, thanks for the awesome tip!

Glad it helped! You might try what I described above if it would be useful, but
if not, well, now you know how to do it. =)