At 10:46 AM 9/28/2001 -0700, Hong Zhang wrote:

> > In a word? Badly. :) Especially when threads were involved, though in some
>
> > ways it was actually better since you were less likely to core perl.
> >
> > Threads and signals generally don't mix well, especially in any sort of
> > cross-platform way. Linux, for example, deals with signals in threaded
> > programs very differently than most other unices do. (Both ways make
>sense,
> > they just aren't at all similar)
>
>Though what you said is largely correct, there are way to use signal safely
>with threads.
>
>Signals are divided into 2 category, sync or async. The sync signals include
>SIGSEGV, SIGBUS etc. They must be handled inside signal handler. As long as
>the crash does not happen inside mutext/condvar block, it will be safe to
>get out of the trouble using siglongjmp on most platforms.

The fun part about async vs sync is there's no common decision on what's an 
async signal and what's a sync signal. :( SIGPIPE, for example, is one of 
those. (Tru64, at least, treats it differently than Solaris)

I generally divide signals into two groups:

  *) Messages from outside (i.e. SIGHUP)
  *) Indicators of Horrific Failure (i.e. SIGBUS)

Generally speaking, parrot should probably just up and die for the first 
type, and turn the second into events.

>Since the pthread_self() may not be available inside signal_handler(), we
>need to design some global data structures to find current interpreter.

AFAIK, almost none of the pthread functions are safe in signal handlers. 
There might be one or two, but I can't remember which ones. (None of the 
mutex or condition functions, alas, and they're rather useful)

>We create one thread for all async signal, and let everyone else mask async
>signal off. This scheme can handle signal reliably under threads.

This, unfortunately, isn't portable. It only works on platforms that fully 
implement the POSIX threading standard. Linux is the big example of a 
platform that *doesn't*. Signals only get delivered to the thread that 
triggered them, and if the thread's got the signal masked off it gets 
dropped. :(

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to