Monday 15 March 2010

c - Linux: Can a signal handler excution be preempted? -


I came across the following signal handler code which stores the wrong variable so that it does not affect the wrong handle of the main thread.

  Invalid myhandler (int signo) {int esaved; Esaved = errno; Write (STDOUT_FILENO, "got a hint \ n", 13); Errno = esaved; }   

But does it really work? What happens if after writing another thread check is check for shared errno varible? And before restoring the error? Can the thread be wrong wrong due to race conditions?

Or a signal handler performs atomic with regard to a thread / process, so that after the signal handler is executed, the kernel will be used until the thread handler is finished Schedule back?

After being placed in other words - execute a signal handler without interruption:

  - 1) Scheduler (process / thread), or - 2) Other signals, or - 3) hardware interrupt handlers?    

variable errno is thread-specific ?? ?? Or, more accurately, in a threaded environment, is a thread-local or per-thread value? So what is done to this errno in this thread will not affect errno in other threads.

The purpose of saving and restoring the code is to hide any error set by write () system call myhandler () . But if write () fails, then it can set some new value to errno ???? It will not be zero, but all this can say about you ??? But the call you are asking about is calling the call after writing write () to start the value again before to write , So that the fact that it is written is 'invisible' in this sense that it does not affect errno for this thread.

The signal indicator function can be interrupted by the signals which are not blocked by signal masks. The sign is that it is reacting. It can also be rescheduled. There may be hardware interrupts, but code will be pressed in view of these effects.


On Linux, you may get /usr/include/bits/errno.h defining the macro error (more than More #ifdef wrapped in code shown here):

  extern int * __ errno_location (zero) __THROW __attribute__ ((__const__)); # If! Defined _LIBC || When using defined _LIBC_REENTRANT / * thread, the error is a per-thread value * / # define the error (* __ error number_position ()) #andif    

No comments:

Post a Comment