I'm new to C, and I'm reading a book which says:
In one common handler design, the handler records the receipt of the signal by writing to a global flag. The main program periodically reads the flag, responds to the signal, and clears the flag. For flags that are shared in this way, C provides an integer data type, sig_atomic_t, for which reads and writes are guaranteed to be atomic (uninterruptible) because they can be implemented with a single instruction:
volatile sig_atomic_t flag;Since they can’t be interrupted, you can safely read from and write to sig_atomic_t variables without temporarily blocking signals
I'm still a little bit confused, below is my questions:
I checked the source code and found that sig_atomic_t is actually int, so why not we just use int as volatile int flag;? do we use sig_atomic_t just for emphasis?