Permit threads other than main() to call exit() and have the process stop.

If a subsidiary thread calls exit(), its context is used (on Solaris at
least) for calling the atexit routines.  If one of those routines cancels
the thread that called exit(), the exit itself gets cancelled and any
remaining threads are left running, possibly including the main() thread.
Thus the check in myAtExit() should have been to not cancel the current
thread; when this was tested, presumably only calls to exit() from the
main() thread were checked.
This commit is contained in:
Andrew Johnson
2003-04-08 19:18:52 +00:00
parent 6f8d94c8dd
commit 9e337cca2b
+3 -1
View File
@@ -94,6 +94,7 @@ if(status) { \
static void myAtExit(void)
{
epicsThreadOSD *pthreadInfo;
epicsThreadOSD *pthreadSelf;
static int ntimes=0;
int status;
@@ -104,9 +105,10 @@ static void myAtExit(void)
}
status = pthread_mutex_lock(&listLock);
checkStatusQuit(status,"pthread_mutex_lock","myAtExit");
pthreadSelf = (epicsThreadOSD *)pthread_getspecific(getpthreadInfo);
pthreadInfo=(epicsThreadOSD *)ellFirst(&pthreadList);
while(pthreadInfo) {
if(pthreadInfo->createFunc){/* dont cancel main thread*/
if(pthreadInfo != pthreadSelf){ /* dont cancel this thread! */
pthread_cancel(pthreadInfo->tid);
}
pthreadInfo=(epicsThreadOSD *)ellNext(&pthreadInfo->node);