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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With