tonysdg
tonysdg

Reputation: 1385

Why is sigwait() MT-safe but sigsuspend() is not?

I'm looking to write a multithreaded application where one thread waits for another to signal it before continuing. According to here, sigsuspend is not MT-safe because of a race condition. According to here, sigwait should be used in these cases. I'm trying to understand why.

Based on the man page descriptions (sigwait and sigsuspend), it appears that...

sigsuspend (const sigset_t *mask) actually changes the process's signal mask, which would affect all threads.

sigwait (const sigset_t *set, int *sig) just waits for one of the indicated signals in set without changing the thread's (or process's) signal mask.

Is this understanding correct? And if so, how does sigwait block without changing the signal mask?

Upvotes: 5

Views: 2045

Answers (1)

terence hill
terence hill

Reputation: 3454

Actually sigwait changes the mask but then restore it, see this (Advanced Programming in the UNIX Environment): Signals and Threads.

And also this: Oracle Multithreaded Programming Guide

Upvotes: 4

Related Questions