Hello, I implemented a simlpe class CTimer, which launch a thread when Start() method is called which should exit when the Stop() method is called. The thread is a simple function with a while loop whose exit condition is m_bExitFlag == true:
The thread routine is this:Code:class CTimer { public: CTimer(); virtual ~CTimer(); void Stop(); void Start(); .... private: static UINT privStartThreadWait( LPVOID pparam); BOOL m_bEndThread; //true if stop is requested .... }
the Stop() method just sets m_bEndThread to true, and so the thread function should exit from the while() loop.Code:UINT CTimer::privStartThreadWait( LPVOID pparam) { CTime currTime; CTimeSpan diffTime; CTimer *pt; pt = (CTimer*)pparam; pt->m_bEndThread = false; pt->m_bThreadStopped = false; do { currTime = CTime::GetCurrentTime(); diffTime = currTime - pt->m_startTime; }while( diffTime < pt->m_ctimTimeout && !pt->m_bEndThread ); pt->m_bThreadStopped = true; AfxEndThread( 0 , true ); return 0; }
THE PROBLEM: the while() loop doesn't exit after I set m_bEndThread from the main thread, calling the Stop() method. I'd like to know if there si something I should know about the interprocess communication, as for example the kind of the members used to do the communication (perhaps should be public, or protected with caller class as friend, or static or something else).
Thank you for any hint.
BrownB



LinkBack URL
About LinkBacks


