From 9e337cca2bbb26c779a717e2923108806e1df0af Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 8 Apr 2003 19:18:52 +0000 Subject: [PATCH] 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. --- src/libCom/osi/os/posix/osdThread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libCom/osi/os/posix/osdThread.c b/src/libCom/osi/os/posix/osdThread.c index bc13e24ca..fe0610a73 100644 --- a/src/libCom/osi/os/posix/osdThread.c +++ b/src/libCom/osi/os/posix/osdThread.c @@ -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);