Thread end, getexitcodethread after end value has been still_active,259 the problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.