Recently in VC + + to write a visual inspection system, which open more threads. It is important to know when a thread is over. The GetExitCodeThread () function is used. The function prototypes are as follows:
BOOL GetExitCodeThread ( HANDLE hThread, LPDWORD lpExitCode );
Where, hthread, represents the handle of the thread to be viewed, Lpexitcode is a DWORD-type pointer that is passed in to save the thread state when the function is called. If the value is not still_active, the thread does not end.
The return value of this function has no relation to the state of the thread. Only indicates whether the function succeeds;
When I use the function again, I get a problem and the thread is over. I can be sure that there is a loop in the thread, and that the loop is no longer executing. But the status code obtained with this function is always still_active, in fact, in the compiler to see the time is 259, converted to 16 is still_active. The code is as follows:
if ( m_pThreadVelocity ) { =0; do { GetExitCodeThread(m_pThreadVelocity->&dwExitCode); } while== dwExitCode ); = NULL; } =&m_VelocityAndMeterThreadParam, THREAD_PRIORITY_TIME_CRITICAL);
Always do not know how to solve, and then a chance to GetExitCodeThread function before the first put, dwexitcode initialized a bit, it becomes normal. The code is as follows:
if (m_pthreadvelocity) { DWORD dwexitcode = 0 Do {Dwexitcode = 0 GetExitCodeThread (M_pthreadvelocity-> m_hthread, & Dwexitcode) } while (still_active == dwexitcode) M_pthreadvelocity = null } m_pthreadvelocity = AfxBeginThread (fnvelocityandmeterthread, & M_velocityandmeterthreadparam, thread_priority_time_critical) ; }
It is not yet known what the reason is, it may be that the function internally assigns a value to the Lpexitcode is not a simple direct assignment. The value of Still_active is one ((DWORD) 0x00000103l), and the DWORD is actually unsigned char. The value of the still_active is actually 16 binary. Conversion into 10 is 259. Here may Lpexitcode assignment is not simple Lpexitcode = XX or the like. So you need to reinitialize the value of Lpexitcode after each execution of Getexitcode.
Thread end, getexitcodethread after end value has been still_active,259 the problem