Next: , Previous: , Up: Defining Handlers   [Contents][Index]


24.4.6 Signal Handling and Nonreentrant Functions

Handler functions usually don’t do very much. The best practice is to write a handler that does nothing but set an external variable that the program checks regularly, and leave all serious work to the program. This is best because the handler can be called asynchronously, at unpredictable times—perhaps in the middle of a primitive function, or even between the beginning and the end of a C operator that requires multiple instructions. The data structures being manipulated might therefore be in an inconsistent state when the handler function is invoked. Even copying one int variable into another can take two instructions on most machines.

This means you have to be very careful about what you do in a signal handler.

A function can be non-reentrant if it uses memory that is not on the stack.


Next: , Previous: , Up: Defining Handlers   [Contents][Index]