C++11 allows the use of atomics in signal handlers. The atomics operations library was designed to support several different applications:
- To communicate between threads in cases in which other synchronization mechanisms such as locks are less appropriate.
- To communicate between processes when other synchronization mechanisms do not support it suitably.
- To allow for communication with signal handlers.
In the last case, locks are generally not usable since the signal handler may have interrupted a thread holding a lock. Depending on whether the lock is reentrant, an attempt to acquire the lock in the handler would either result in deadlock, or in two logically distinct tasks acquiring the lock at the same time.
When the processing of the abstract machine is interrupted by receipt of a signal, the values of objects which are neither,
- of type volatile std::sig_atomic_t, nor
- a lock-free atomic object
are unspecified, and the value of any object not in either of these two categories that is modified by the handler becomes undefined.
The common subset of the C and C++ languages consists of all declarations, definitions, and expressions that may appear in a well formed C++ program and also in a conforming C program. A POF (plain old function) is a function that uses only features from this common subset, and that does not directly or indirectly use any function that is not a POF. All signal handlers shall have C linkage. A POF that could be used as a signal handler in a conforming C program does not produce undefined behavior when used as a signal handler in a C++ program. The behavior of any other function used as a signal handler in a C++ program is implementation-defined.