I came across the following signal handler code that stores the errno variable so that it wont affect main thread's errno handling.
void myhandler(int signo)
{
int esaved;
esaved = errno;
write(STDOUT_FILENO, "Got a signal\n", 13);
errno = esaved;
}
But this really serves the purpose ? what happens if another thread check for the shared errno varible just after write() and before restoring errno ? Will that thread get wrong errno value due to race condition?
Or a signal handler executes atomically with respect to a thread/process, so that once the signal handler executes , kernel wont schedule the thread back until the signal handler finishes?
Putting in other words -Once started, do a signal handler executes without being interrupted by:
- 1) Scheduler (process/threads), or
- 2) Other signals, or
- 3) Hardware interrupt handlers ?