atomic_flag is a C atomic type whose flag operations appear indivisible in signal-handler contexts. This makes it suitable for passing limited state from an asynchronous signal handler to the interrupted program. section 17.7 section 17.6
Use atomic_flag within the narrow boundary imposed by asynchronous signals:
- Keep the handler minimal: mark the interrupt condition, return to the interrupted context, and handle the condition there. section 17.7 section 17.6
- Treat an uninterruptible operation as one observed either before it starts or after it completes; the implementation may still divide it internally. section 17.6
- Distinguish atomic_flag from sig_atomic_t: sig_atomic_t reliably supports only indivisible evaluation and assignment, so it is unsuitable for counters. section 17.6
- Remember that atomic_flag belongs to the C11 atomic facilities and requires stdatomic.h when atomics are available; __STDC_NO_ATOMICS__ signals their absence. section 17.6
Signal-handler boundary
A minimal handler updates signal-related state, handles immediate termination cases, or stores the interrupt value before returning. The interrupted context then performs the substantial work. atomic_flag is one permitted type for communicating that limited state; the surrounding example also conditionally counts handler calls with a lock-free atomic type. section 17.7

