31 AlternateThreadPT::AlternateThreadPT()
32 : _threadStatus(UNEXISTING)
44 }
catch (
const exception & e) {
45 cerr <<
"Exception happened in AlternateThreadPT destructor: " << e.what() << endl;
47 cerr <<
"Unknown exception happened in AlternateThreadPT destructor." << endl;
77 DEBTRACE(
"Master is trying to terminate slave by signaling error")
83 cerr <<
"Warning: Slave thread in AlternateThread did not end properly. "
84 "Thread will be canceled." << endl;
103 DEBTRACE(
"AlternateThread terminated")
109 DEBTRACE(
"Master signaling slave and waiting");
117 DEBTRACE(
"Slave signaling master and waiting");
144 DEBTRACE(
"Slave thread is now running")
148 pthread_cleanup_pop(1);
149 }
catch (
const exception & e) {
150 cerr <<
"Unrecoverable error: an exception was caught in AlternateThread "
151 "(exceptions should normally be caught before getting here). "
152 "Exception type is: " <<
typeid(e).name() <<
", message is: " <<
169 DEBTRACE(
"Cleaning up slave thread")
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
This class provides a mechanism to run two threads alternately.
ThreadStatus _threadStatus
pthread_mutex_t _pingPongMutex
virtual void signalSlaveAndWait()
Block the master thread and release the slave thread.
bool isTerminationRequested() const
Return true if the master requested the slave thread termination.
virtual ~AlternateThreadPT()
virtual void run()=0
This method must be implemented in subclasses and will be run in the slave thread.
virtual void signalMasterAndWait()
Block the slave thread and release the master thread.
ThreadStatus getThreadStatus() const
Return the thread status.
void terminateSlaveThread()
Terminate the slave thread.
static void threadCleanupFct(void *instance)
pthread_cond_t _pingPongCond
void start()
Create and launch the slave thread.
static void * runThread(void *instance)