Subj : Re: asynchronous cancel vs calling pthread_exit in signal handler To : comp.unix.programmer,comp.programming.threads From : Ben Hutchings Date : Fri Apr 22 2005 10:15 pm Dave wrote: > I'm a newbie in MT programming and I've been reading PwPT about > cancelling the execution of a thread. > > I'm writing a database application which calls some 3rd party library > to send SQL queries to the database but sometimes the database is not > responsive and I would like to interrupt the call. Sending a signal > doesn't interrupt the call every time so I would like to > cancel/terminate the thread (deferred cancel doesn't work either). > > From what I've read it seems that asynchronous cancel is definitely > something that I shouldn't use. but I came across a suggestion of > calling pthread_exit() in the signal handler, I wonder if that's just > as dangerous as using asynchronous cancel? I don't think any of the pthreads functions are safe to call in a signal handler. They're not listed in the table of signal-safe functions in the latest version of SUS. In any case exiting a thread from a signal handler is liable to leave shared data in an invalid state, just like asynchronous cancellation. > Any help is appreciated. Thanks in advance. -- Ben Hutchings If the facts do not conform to your theory, they must be disposed of. .