which running thread gests the external signal

Alin-Adrian Anton aanton at spintech.ro
Tue May 2 17:59:07 UTC 2006

Daniel Eischen wrote:
> POSIX states any thread that is in sigwait() (with the specified
> signal in the wait mask), or has the signal unmasked (in the threads
> signal mask) can receive the signal.  If you want a certain thread
> to receive a process-wide signal, then the only sure way (POSIX) to
> do that is to block the signal in all the threads with the exception
> of the thread that is to receive the signal.

OK, I was able to delegate a single thread for handling all the signals, 
by using sigprocmask to block all signals at the beggining, then using 
pthread_sigmask to unblock the needed signals inside the delegated 
thread. This seemed to be the cleanest way of doing it..

However, this is not fully clean: all the other threads should *ignore* 
the signals, not *block* them. Blocking a signal means the signal will 
be queued and the queue will eventually fill, and so on. In my scenario 
I get the result without running into problems (because each thread 
seems to have it's own signal queue), however it's not... "clean". The 
other threads need to simply 'drop' the signals, not cause them to be 
queued forever (consider an uptime of 1 year?). I don't know the impact, 
however I want it to be clean..

So ... would it be a way to ignore the signals from all the other 
threads except the delegated one for handling them? (I'm sorry, I don't 
notice it, even if it's obvious)

Thanks for the advices and the tips, it's been really usefull.

PS: Without using sigprocmask and pthread_sigmask, one random thread is 
stopped in order for the signal handler to execute. Doesn't this mean 
that the other threads are not 'seeing' the signal? In order to force a 
thread to receive/see the signal, I need to block the signal inside all 
the other threads (either with sigprocmask in main, or with 
pthread_sigmask). On Linux, the signal gets delivered to all the running 
threads, unless specifically blocked :). And I think that conformes to 
your mentioning of POSIX standards.

Sorry if I'm wrong.

> I would recommend you also visit
> http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html

I've read it, thanks. I added it to my bookmarks.

Yours Sincerely,
Alin-Adrian Anton
GPG keyID 0x183087BA (B129 E8F4 7B34 15A9 0785  2F7C 5823 ABA0 1830 87BA)
gpg --keyserver pgp.mit.edu --recv-keys 0x183087BA

"It is dangerous to be right when the government is wrong." - Voltaire

More information about the freebsd-hackers mailing list