On my Linux box, sig_atomic_t is a plain old int. Do ints posses a special atomic quality?
$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
...
Thread model: posix
gcc version 4.3.2 (Debian 4.3.2-1.1)
$ echo '#include <signal.h>' | gcc -E - | grep atomic
typedef int __sig_atomic_t;
typedef __sig_atomic_t sig_atomic_t;
C99
sig_atomic_tconforms only to a very weak definition of "atomicity", because C99 has no concept of concurrency, only interruptibility. (C2011 adds a concurrency model, and with it the_Atomictypes that make stronger guarantees; however, AFAIKsig_atomic_tis unchanged, since its raison d’être is still communication with signal handlers, not across threads.)This is everything C99 says about
sig_atomic_t:The term "atomic entity" is not defined anywhere in the standard. Translating from standards-ese, the intent is that the CPU can completely update a variable of type
sig_atomic_tin memory ("static storage duration") with one machine instruction. Thus, in the concurrency-free, precisely interruptible C99 abstract machine, it is impossible for a signal handler to observe a variable of typesig_atomic_thalfway through an update. The §7.18.3p3 language licenses this type to be as small ascharif necessary. Note please the complete absence of any language relating to cross-processor consistency.There are real CPUs which require more than one instruction to write a value larger than
charto memory. There are also real CPUs which require more than one instruction to write values smaller than a machine word (often, but not necessarily, the same asint) to memory. The language in the GNU C Library manual is now inaccurate. It represents a desire on the part of the original authors to eliminate what they saw as unnecessary license for C implementations to do weird shit that made life harder for application programmers. Unfortunately, that very license is what makes it possible to have C at all on some real machines. There is at least one embedded Linux port (to the AVR) for which neitherintnor pointers can be written to memory in one instruction. (People are working on making the manual more accurate, see e.g. http://sourceware.org/ml/libc-alpha/2012-02/msg00651.html —sig_atomic_tseems to have been missed in that one, though.)