What if we must access some global state within our signal handler routine? There do exist some alternate ways of making it signal-safe:
- At the point you must access these variables, ensure that all signals are blocked (or masked), and, once done, restore the signal state (unmask).
- Perform some kind of locking on shared data while accessing it.
- In multiprocess applications (the case we are talking about here), (binary) semaphores can be used as a locking mechanism to protect shared data across processes.
- In multithreaded applications, the use of an appropriate locking mechanism (mutex locks, perhaps; we shall, of course, cover this in a later chapter in detail).
If your requirement is ...