Laszlo Ersek <ler...@redhat.com> writes: > On 09/15/11 21:44, Peter Maydell wrote: >> On 15 September 2011 18:22, Laszlo Ersek<ler...@redhat.com> wrote: >>> -int no_shutdown = 0; >>> +volatile int no_shutdown = 0; >> >> So why 'volatile' and not 'sig_atomic_t', then? > > The sigaction() spec says"volatile sig_atomic_t", so that would be > ideal. My assumption was that "sig_atomic_t" (which is allowed by > POSIX not to be wider than "char") would be in practice at least as
Inherited from the C standard. > wide as "int" and "pid_t". Should my assumption be wrong on some > platforms, qualifying the variables "volatile" while keeping their > current types (int / pid_t) does less damage (no damage) than > narrowing their types. info libc says: In practice, you can assume that `int' is atomic. You can also assume that pointer types are atomic; that is very convenient. Both of these assumptions are true on all of the machines that the GNU C library supports and on all POSIX systems we know of. If you're programming for a machine where int isn't atomic, you very likely got more serious issues to worry about :) Non-atomic pid_t would be weird, but not quite as weird as non-atomic int. Regardless, no_shutdown is used like bool, so you could easily make it sig_atomic_t.