From a7a6c01bea61c44a85568bbbad669baedba6907e Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 6 Jan 2009 23:06:25 +0000 Subject: [PATCH] Removed the pthread_cancel() functionality from posix/osdThread.c, resolving the whole issue with catch(...) on NPTL. --- src/libCom/osi/epicsThread.cpp | 13 +++++----- src/libCom/osi/os/posix/osdThread.c | 38 +---------------------------- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/libCom/osi/epicsThread.cpp b/src/libCom/osi/epicsThread.cpp index 4f53eb284..f31d445c0 100644 --- a/src/libCom/osi/epicsThread.cpp +++ b/src/libCom/osi/epicsThread.cpp @@ -57,10 +57,11 @@ extern "C" void epicsThreadCallEntryPoint ( void * pPvt ) errlogPrintf ( "epicsThread: Unexpected C++ exception \"%s\" with type \"%s\" in thread \"%s\" at %s\n", except.what (), typeid ( except ).name (), name, date ); + errlogFlush (); // this should behave as the C++ implementation intends when an // exception isnt handled. If users dont like this behavior, they // can install an application specific unexpected handler. - std::unexpected (); + std::unexpected (); } } catch ( ... ) { @@ -74,13 +75,11 @@ extern "C" void epicsThreadCallEntryPoint ( void * pPvt ) "epicsThread: Unknown C++ exception in thread \"%s\" at %s\n", name, date ); errlogFlush (); + // this should behave as the C++ implementation intends when an + // exception isnt handled. If users dont like this behavior, they + // can install an application specific unexpected handler. + std::unexpected (); } - // The Linux NPTL library requires us to re-throw here; it uses - // an untyped exception object to shut down threads when we call - // pthread_cancel() in the os/posix/osdThread.c myAtExit() - // handler, and aborts with "FATAL: exception not rethrown" if - // we don't re-throw it. This solution is incomplete though... - throw; } if ( ! waitRelease ) { epicsGuard < epicsMutex > guard ( pThread->mutex ); diff --git a/src/libCom/osi/os/posix/osdThread.c b/src/libCom/osi/os/posix/osdThread.c index 1dd587f97..971095bbb 100644 --- a/src/libCom/osi/os/posix/osdThread.c +++ b/src/libCom/osi/os/posix/osdThread.c @@ -111,42 +111,6 @@ if(status) { \ exit(-1);\ } -/* myAtExit just cancels all threads. Someday propercleanup is needed*/ -static void myAtExit(void) -{ - epicsThreadOSD *pthreadInfo; - epicsThreadOSD *pthreadSelf; - static int ntimes=0; - int status; - - ntimes++; - if(ntimes>1) { - fprintf(stderr,"osdThread myAtExit extered multiple times\n"); - return; - } - epicsExitCallAtExits(); - status = mutexLock(&listLock); - checkStatusQuit(status,"pthread_mutex_lock","myAtExit"); - pthreadSelf = (epicsThreadOSD *)pthread_getspecific(getpthreadInfo); - if(pthreadSelf==NULL) - pthreadSelf = createImplicit(); - pthreadInfo=(epicsThreadOSD *)ellLast(&pthreadList); - while(pthreadInfo) { - if(pthreadInfo != pthreadSelf /*dont cancel this thread*/ - && (strcmp("_main_",pthreadInfo->name)!=0)){/* dont cancel main*/ - pthread_cancel(pthreadInfo->tid); - } - pthreadInfo=(epicsThreadOSD *)ellPrevious(&pthreadInfo->node); - } - status = pthread_mutex_unlock(&listLock); - checkStatusQuit(status,"pthread_mutex_unlock","myAtExit"); - - /* delete all resources created by once */ - free(pcommonAttr); pcommonAttr=0; - pthread_mutex_destroy(&listLock); - pthread_mutex_destroy(&onceLock); - pthread_key_delete(getpthreadInfo); -} #if defined (_POSIX_THREAD_PRIORITY_SCHEDULING) static int getOssPriorityValue(epicsThreadOSD *pthreadInfo) @@ -291,7 +255,7 @@ static void once(void) pthreadInfo->isOnThreadList = 1; status = pthread_mutex_unlock(&listLock); checkStatusQuit(status,"pthread_mutex_unlock","epicsThreadInit"); - status = atexit(myAtExit); + status = atexit(epicsExitCallAtExits); checkStatusOnce(status,"atexit"); epicsThreadOnceCalled = 1; }