A signal can interrupt an operation partway through. An uninterruptible operation appears either not to have started or to have finished when the signal handler runs. A lock-free atomic type provides this property without relying on a hidden lock. section 19.6
TAKEAWAY: Do not use sig_atomic_t as a signal-handler counter. Its loads and stores are uninterruptible, but ++ may split into a load, increment, and store. For counting, use an atomic type only when it has the lock-free property. section 19.6
#if ATOMIC_LONG_LOCK_FREE > 1
/**
** @brief Keep track of the number of calls into a
** signal handler for each possible signal.
**
** Don't use this array directly.
**
** @see sh_count to update this information.
** @see SH_PRINT to use that information.
**/
extern _Atomic(unsigned long) sh_counts[];
/**
** @brief Use this in your signal handler to keep track of the
** number of calls to the signal @a sig.
**
** @see sh_counted to use that information.
**/
inline
void sh_count(int sig) {
if (sig < sh_known) ++sh_counts[sig];
}
inline
unsigned long sh_counted(int sig){
return (sig < sh_known) ? sh_counts[sig] : 0;
}
#else
The conditional example enables an _Atomic(unsigned long) signal counter only when ATOMIC_LONG_LOCK_FREE > 1; sh_count then increments it in the handler. section 19.6


