Subj : Re: asynchronous cancel vs calling pthread_exit in signal handler To : comp.unix.programmer,comp.programming.threads From : Ben Hutchings Date : Sat Apr 23 2005 09:48 pm Dave wrote: > so what is the general rule? > (1) If I'm sure that the signal doesn't interrupt any > nonasync-signal-safe functions, can I call nonasync-signal-safe > function in the signal handler? I believe so. > The example Marc Rochkind gave in this Advanced Unix Programming book > uses _exit instead of exit to terminate a process. This is allowed because _exit does only minimal cleanup of resources shared between processes. Signals never interrupt the critical sections associated with management of such resources. The same is not true of per-process resources such as the malloc() heap and stdio streams. > So by saying leaving shared data in invalid state what kind of > shared data is being referred to? Aside from any data your program explicitly shares between threads, there's the malloc() heap, stdio streams, locale information, the dynamic linker's state, and many other things. > If I used exit() instead _exit() to terminate a process in a signal > handler would that possibly cause the OS or other processes to exhibit > undefined behavior? Not on a normal Unix system, unless the processes share memory. -- Ben Hutchings I haven't lost my mind; it's backed up on tape somewhere. .