Well, as I understand it, sig_atomic_t is an integer type that
can be accessed "as an atomic entity",
Only in certain contexts, for a restricted set of operations.
In fact, I'm not sure that you could call the guarantees
involving it "atomic".
which means that an operation on it takes a single machine
instruction.
That's not the definition of atomic. Lot's of operations which
only take a single machine instruction aren't atomic. (A lot of
processors can implement ++ i in a single instruction, provided
the results are not used; I don't know of any where it is
atomic.) And it's quite possible to design atomic operations
involving more than one instruction.
(I'm not sure which operations exactly, but the reference I'm
reading mentions "fetching" its value and assigning a value to
it.)
Isn't this what the OP asked about?
He mentionned i++, amongst other things. That isn't atomic,
even on a sig_atomic_t.
The *current* Standard does not say it's "likely to be defined as int".
And the operations on that type are *not* defined [as atomic or even
at all].
Why does it have "atomic" in its name then?
You'd have to ask the people who designed it (or named it).
It's "atomicity" is very restrained.
When you speak about "atomicity", you have to specify the
context somewhat. A lot of operations, for example, will be
"atomic" on a single processor machine, but not if multiple
CPU's are involved. Concerning sig_atomic_t, the C standard
(and the C++ standard, by reference) says that it is the
"integer type of an object that can be accessed as an atomic
entity, even in the presence of asynchronous interrupts." The
only "context" refered to is "the presence of asynchronous
interrupts". Furthermore, it states that "the behavior is
undefined if the signal handler refers to any object with static
storage duration other than by assigning a value to an object
declared as volatile sig_atomic_t, or the signal handler calls
any function in the standard library other than the abort
function, the _Exit function, or the signal function with the
first argument equal to the signal number corresponding to the
signal that caused the invocation of the handler." That's
awfully restrictive.
It doesn't necessarily relate to threads. The purpose of
sig_atomic_t is to allow a signal handler to manipulate an
integer variable with static storage duration without the risk
that the handler is invoked during an operation on the
variable (leaving the variable with a garbage value).
The problem is that the standard doesn't really guarantee this.
The standard doesn't say much of anything about what happens
when you modify sig_atomic_t outside of a signal handler.