On Wed, 21 Feb 2007, William James wrote:

On 2/21/07, James Carlson <[EMAIL PROTECTED]> wrote:
William James writes:
> On 2/21/07, Vincenzo Sciarra <[EMAIL PROTECTED]> wrote:
> > All threads receive the signal. Better, the main thread receive the signal but it shares the signal with other threads.
> >
> >
> >
> > Dott. Vincenzo Sciarra
>
> So all  threads call the signal callback at the same time? Can I use
> pthread_mutex_lock() in the signal handler to prevent a race
> condition?

There's no race.  For async signals, system just picks one thread for
delivery.

This is bad. Is there no function to define that signals should be
send to all threads for async signals?

I must say you're asking strange questions.

What could you gain by dispatching a signal more than once ? Why would you want a thundering herd of N threads attempting to handle a signal, only so that in the end N-1 of them find in their signal handler that it's no longer pending because whoever came first did away with it ?

You can have all async signals targeted at a specific thread by setting every thread's signal mask to "ignore" except the one that you wish to do the signal processing in; that remaining 'signal daemon' one can then simply sigwait() for whatever happens.

As far as thread synchronization / inter-thread communication goes, signals aren't exactly a great mechanisms. You'd rather use things like condition variables (which can be 'signaled'), or one of the other synchronization primitives designed for threads.

FrankH.
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to