From c9dcab95a6aa7376edde322d3b9473e9a89c2b38 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 4 Apr 2018 11:28:08 -0700 Subject: [PATCH] class epicsThread is joinable --- modules/libcom/src/osi/epicsThread.cpp | 22 +++++++++++++++++++--- modules/libcom/src/osi/epicsThread.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/libcom/src/osi/epicsThread.cpp b/modules/libcom/src/osi/epicsThread.cpp index 4f983f0e3..52819c8eb 100644 --- a/modules/libcom/src/osi/epicsThread.cpp +++ b/modules/libcom/src/osi/epicsThread.cpp @@ -153,6 +153,10 @@ bool epicsThread::exitWait ( const double delay ) throw () if ( this->pThreadDestroyed ) { *this->pThreadDestroyed = true; } + if(!joined) { + epicsThreadJoin(this->id); + joined = true; + } return true; } epicsTime exitWaitBegin = epicsTime::getCurrent (); @@ -166,6 +170,10 @@ bool epicsThread::exitWait ( const double delay ) throw () epicsTime current = epicsTime::getCurrent (); exitWaitElapsed = current - exitWaitBegin; } + if(!joined) { + epicsThreadJoin(this->id); + joined = true; + } } catch ( std :: exception & except ) { errlogPrintf ( @@ -190,10 +198,18 @@ epicsThread::epicsThread ( unsigned stackSize, unsigned priority ) : runable ( runableIn ), id ( 0 ), pThreadDestroyed ( 0 ), begin ( false ), cancel ( false ), terminated ( false ) + , joined(false) { - this->id = epicsThreadCreate ( - pName, priority, stackSize, epicsThreadCallEntryPoint, - static_cast < void * > ( this ) ); + epicsThreadOpts opts; + epicsThreadOptsDefaults(&opts); + opts.stackSize = stackSize; + opts.priority = priority; + opts.joinable = 1; + + this->id = epicsThreadCreateOpt( + pName, epicsThreadCallEntryPoint, + static_cast < void * > ( this ), + &opts); if ( ! this->id ) { throw unableToCreateThread (); } diff --git a/modules/libcom/src/osi/epicsThread.h b/modules/libcom/src/osi/epicsThread.h index 0482bea34..c43d7fb01 100644 --- a/modules/libcom/src/osi/epicsThread.h +++ b/modules/libcom/src/osi/epicsThread.h @@ -197,6 +197,7 @@ private: bool begin; bool cancel; bool terminated; + bool joined; bool beginWait () throw (); epicsThread ( const epicsThread & );