Namespaces
Variants
Views
Actions

sig_atomic_t

From cppreference.com
< c‎ | program
Revision as of 07:21, 21 April 2014 by Newatthis (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Defined in header <signal.h>
typedef /* unspecified */ sig_atomic_t;

An integer type which can be accessed as an atomic entity even in the presence of asynchronous interrupts made by signals.

[edit] Example

#include <signal.h>
#include <stdio.h>
 
volatile sig_atomic_t gSignalStatus = 0;
 
void signal_handler(int signal)
{
    gSignalStatus = signal;
}
 
int main(void)
{
    /* Install a signal handler. */
    signal(SIGINT, signal_handler);
 
    printf("SignalValue:   %d\n", gSignalStatus);
    printf("Sending signal %d\n", SIGINT);
    raise(SIGINT);
    printf("SignalValue:   %d\n", gSignalStatus);
}

Possible output:

SignalValue:   0
Sending signal 2
SignalValue:   2

[edit] See also

sets a signal handler for particular signal
(function) [edit]
C++ documentation for sig_atomic_t