6 ms·
This won't work for: 1. Larger than word size variables 2. Out of order CPUs 3. On multicore CPUs when another core handles the signal Atomics must be used
by dnedic 3y ago
This won't work for:
1. Larger than word size variables
2. Out of order CPUs
3. On multicore CPUs when another core handles the signal
Atomics must be used here for proper synchronization, when they are available. If not, architecture-specific mechanisms should be used.
- kazinator 3y agoThis existed before threads were introduced into the C language. It's only about a single control flow being interrupted by signal, remaining suspended while the handler executes. As soon as the suspended code resumes, the updated sig_atomic_t value is visible to it, and the whole value (not some torn mix of the old a new value). It has nothing to do with threads or cores; if one thread runs a handler and another looks at the flag, it's not even relevant that a signal handler is involved. The sig_atomic_t type that is specified for that purpose and must be used, which rules out the uncertainty you're referring to in (1). It is not a type qualifier but a specifier.