[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

8733.0. "why sigwait could wait on multiple signals ?" by TAEC::GARNERO () Thu Feb 06 1997 05:40

Hello,

after the response given in note 8726.2, I have a concern about the sigwait
call.
In fact, I think that it is not reliable to use sigwait with a set of signals
which contains more that 1 unique signal.

Examine the following situation where a program has to deal with only 2 signals:
  . SIGINT  -> to stop the process
  . SIGXCPU -> which could be used to manage a POSIX timer.

  * suppose that all the threads of the program have blocked these 2 signals
    from delivery
  * 1 service thread is in charge to "sigwait" these 2 signals and perform
    some processing.

If the POSIX timer expires, the service thread will catch this signal, that is:
  . exit from the sigwait call
  . do something 

If during the "do something" a SIGINT signal is raised, this signal will
be discarded because each thread (including the service thread) have this signal
blocked.

So the solution is to create 1 service thread for each signal that has to be 
processed.

Then could someone tell me why the signature of sigwait allows this function
to wait on multiple signals instead of waiting on only one signal ?

Thanks in advance.

/Pierre
T.RTitleUserPersonal
Name
DateLines
8733.1DCETHD::BUTENHOFDave Butenhof, DECthreadsThu Feb 06 1997 08:0316
>If during the "do something" a SIGINT signal is raised, this signal will
>be discarded because each thread (including the service thread) have this
>signal blocked.

Your error is in assuming that the signal would be "discarded". It will
remain pending until either SIGINT is unblocked in some thread, or some
thread calls sigwait() specifying SIGINT as one of the signals. A signal is
only discarded if it is already pending (assuming it's not set into queued
signal mode), or if the signal action is set to "ignore" (SIG_IGN).

Using sigwait to wait on multiple signals works just fine. There are some
situations where you might want to use separate threads, though. For example,
if processing some signal might take "a while", and you need to ensure rapid
response to another signal.

	/dave