Skip to content
Advertisement

linux: sigwait() takes precedence over pthread_sigmask(SIG_UNBLOCK)?

In a program, SIGCHLD is blocked from main thread, then

  1. thread “THREAD_1” is doing sigwait(),
  2. thread “THREAD_2” which forks a child process and kills it, in this thread I called pthread_sigmask(SIG_UNBLOCK, &set, 0) to unblock SIGCHLD before killing the child.

But SIGCHLD is still being picked up by sigwait().

Other than unblock SIGCHLD from main() before creating threads, is there a way to make SIGCHLD bypass sigwait() ? I do not want sigwait() to handle SIGCHILD.

Thanks,

Advertisement

Answer

This behavior is permissible per the spec:

Signals generated for the process shall be delivered to exactly one of those threads within the process which [thread] is in a call to a sigwait() function selecting that signal or [which thread] has not blocked delivery of the signal.

(Emphasis added.)

Simply remove SIGCHLD from the waiting thread’s selection mask and the program will do what you want.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement