Date: Tue, 02 May 2006 20:58:56 +0300 From: Alin-Adrian Anton <aanton@spintech.ro> To: Daniel Eischen <deischen@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: which running thread gests the external signal Message-ID: <44579DE0.1050207@spintech.ro> In-Reply-To: <Pine.GSO.4.64.0605012044390.25456@sea.ntplx.net> References: <4456A5B3.2010809@spintech.ro> <Pine.GSO.4.64.0605012044390.25456@sea.ntplx.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44579DE0.1050207>