????????????_endthreadex??


void __cdecl _endthreadex (unsigned retcode) {
    _ptiddata ptd; // Pointer to thread's data block

    // Clean up floating-point support (code not shown).
    // Get the address of this thread's tiddata block.
    ptd = _getptd_noexit ();


    // Free the tiddata block.
    if (ptd != NULL)
        _freeptd(ptd);
    // Terminate the thread.
    ExitThread(retcode);
    }
 


????????_endthreadex????????????????

????1??C???п??_getptd_noexit????????????ò???????TlsGetValue??????????????????????tiddata?????????

????2?????_endthreadex??????????????????ò???????ExitThread???????????????????????????????????????

?????????????????ExitThread????????????????“???”?????????????????????????е??????????????????з?????????????κ?C++???????????????????????????_tiddata???鱻???????ó?????????й?????????????????????

??????????t?????C/C++???п?????_beginthreadex??_endthreadex??????????????ò??????????????CreateThread??ExitThread????

????????????α???

????HANDLE GetCurrentProcess();
????HANDLE GetCurrentThread();

????????????????????????????????????????????????????α????????????????????????????????????????????????????????????????????????????????????????????????????ü????????????CloseHandle???????????????“α???”??CloseHandle????????????á?

??????α?????????????????DuplicateHandle???????????????????????????????д?????????????


<SPAN style="FONT-SIZE: 14px">    DuplicateHandle(
           GetCurrentProcess()??     // Handle of process that thread
                                                // pseudohandle is relative to
           GetCurrentThread()??    // Parent thread's pseudohandle
           GetCurrentProcess()??  // Handle of process that the new?? real??
                                                // thread handle is relative to
            &hThreadParent??        // Will receive the new?? real?? handle
                                             // identifying the parent thread
            0?? // Ignored due to DUPLICATE_SAME_ACCESS
            FALSE?? // New thread handle is not inheritable
            DUPLICATE_SAME_ACCESS); // New thread handle has same </SPAN>