全部博文(174)
分类: LINUX
2009-04-17 10:54:23
|
|
If one of the signals specified in the set is pending at the time sigwait is called, then sigwait will return without blocking. Before returning, sigwait removes the signal from the set of signals pending for the process. To avoid erroneous behavior, a thread must block the signals it is waiting for before calling sigwait. The sigwait function will atomically unblock the signals and wait until one is delivered. Before returning, sigwait will restore the thread's signal mask. If the signals are not blocked at the time that sigwait is called, then a timing window is opened up where one of the signals can be delivered to the thread before it completes its call to sigwait.
sigwait函数将等待指定的信号到来,调用时,它会自动将指定的信号从屏蔽中去除;返回前,它将恢复原来的屏蔽集。你应该在调用前屏蔽指定的信号。
The advantage to using sigwait is that it can simplify signal handling by allowing us to treat asynchronously-generated signals in a synchronous manner. We can prevent the signals from interrupting the threads by adding them to each thread's signal mask. Then we can dedicate specific threads to handling the signals. These dedicated threads can make function calls without having to worry about which functions are safe to call from a signal handler, because they are being called from normal thread context, not from a traditional signal handler interrupting a normal thread's execution.
sigwait的一个优点是使得异步信号以同步的方式被处理,即在线程的上下文中被处理。而不是传统的使用signal handler打断线程的执行。
If multiple threads are blocked in calls to sigwait for the same
signal, only one of the threads will return from sigwait when the
signal is delivered. If a signal is being caught (the process has established a
signal handler by using sigaction, for example) and a thread is waiting
for the same signal in a call to sigwait, it is left up to the
implementation to decide which way to deliver the signal. In this case, the
implementation could either allow sigwait to return or invoke the
signal handler, but not both.
如果多个线程在等待一个信号,只有一个线程能够收到该信号。如果一个信号被一个信号处理函数俘获,同时被等待,那么它们只有一个会被满足。
向一个线程发送信号
|