wei
wei

Reputation: 6899

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,

Upvotes: 1

Views: 483

Answers (1)

pilcrow
pilcrow

Reputation: 58629

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.

Upvotes: 1

Related Questions