• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            面對現實,超越自己
            逆水行舟,不進則退
            posts - 269,comments - 32,trackbacks - 0

            GetExitCodeThread函數是獲得線程的退出碼, 

            函數: GetExitCodeThread()

            功能:獲取一個結束線程的返回值

            函數原形: BOOL GetExitCodeThread( HANDLE hThread, LPDWORD lpExitCode);

            參數: hThread 指向欲獲取返回值的線程對象的句柄

                           lpExitCode 用于存儲線程的返回值

            返回值:函數執行成功則返回非0值,否則返回 0FALSE

            第一個參數是線程句柄,用 CreateThread 創建線程時獲得到。

            第二個參數是一個 DWORD的指針,用戶應該使用一個 DWORD 類型的變量去接收數據,返回的數據是線程的退出碼,
            通過線程退出碼可以判斷線程是否正在運行,還是已經退出。或者可以判斷線程是否是正常退出還是異常退出。

            執行成功時,存放線程的狀態碼,如果是線程的返回值,表示線程執行完,  如果線程沒執行完,返回STILL_ACTIVE,如果線程的返回值就是STILL_ACTIVE,就無法判斷  .


            MSDN解釋:

            GetExitCodeThread Function

            Retrieves the termination status of the specified thread.

             

            BOOL WINAPI GetExitCodeThread(   __in           HANDLE hThread,    __out         LPDWORD lpExitCode ); 

            Parameters

            hThread

            A handle to the thread.

            The handle must have the THREAD_QUERY_INFORMATION access right. For more information, see Thread Security and Access Rights.

            lpExitCode

            A pointer to a variable to receive the thread termination status. If the specified thread has not terminated and the function succeeds, the termination status returned is STILL_ACTIVE.

            Return Value

            If the function succeeds, the return value is nonzero.

            If the function fails, the return value is zero. To get extended error information, call GetLastError.

            Remarks

            If the thread has terminated and the function succeeds, the termination status returned may be one of the following:

             

            • The exit value specified in the ExitThread or TerminateThread function.
            • The return value from the thread function.
            • The exit value of the thread's process.

            Warning  If a thread happens to return STILL_ACTIVE (259) as an error code, applications that test for this value could end up in an infinite loop.


            參考例子:
             1 int main()     
             2 {         
             3     DWORD exitCode1 = 0;     
             4     DWORD exitCode2 = 0;     
             5     DWORD threadId;          
             6   
             7     HANDLE hThrd1 = CreateThread(NULL, 0,   ThreadFunc1, 0, 0, &threadId );  
             9     if (hThrd1)     
            10         printf("Thread 1 launched\n");    
            11 
            13     HANDLE hThrd2 = CreateThread(NULL, 0,  ThreadFunc2, 0, 0, &threadId );     
            14     if (hThrd2)     
            15         printf("Thread 2 launched\n");    
            16 
            18     for (;;)      
            19     {   
            20           printf("Press any key to exit..\n");   
            21           getch();   
            22           GetExitCodeThread(hThrd1, &exitCode1);   
            23           GetExitCodeThread(hThrd2, &exitCode2);   
            24           if ( exitCode1 == STILL_ACTIVE )   
            25               puts("Thread 1 is still running!");   
            26   
            27           if ( exitCode2 == STILL_ACTIVE )   
            28               puts("Thread 2 is still running!");   
            29           if ( exitCode1 != STILL_ACTIVE   && exitCode2 != STILL_ACTIVE )   
            30               break;   
            31     }   
            32   
            33     CloseHandle(hThrd1);   
            34     CloseHandle(hThrd2);   
            35    
            36     printf("Thread 1 returned %d\n", exitCode1);   
            37     printf("Thread 2 returned %d\n", exitCode2);   
            38     return EXIT_SUCCESS;     
            39 }    
            40   
            41 DWORD WINAPI ThreadFunc1(LPVOID n)   
            42 {   
            43      Sleep((DWORD)n*1000*2);   
            44      return (DWORD)n * 10;   
            45 } 
            46 
            48 DWORD WINAPI ThreadFunc2(LPVOID n)   
            49 {   
            50      Sleep((DWORD)n*1000*2);   
            51      return (DWORD)n * 10;   
            52 } 
            posted on 2013-07-31 11:37 王海光 閱讀(5840) 評論(0)  編輯 收藏 引用 所屬分類: MFC
            久久精品国产精品亚洲毛片| 久久精品国产福利国产琪琪| 日韩人妻无码精品久久免费一 | 思思久久99热只有频精品66| 久久久久青草线蕉综合超碰| 国产亚洲精久久久久久无码| 久久久久亚洲AV成人网人人软件| 久久人人爽人人爽人人片AV不 | 国产成人精品久久亚洲高清不卡 | 久久久久亚洲AV成人网人人软件 | 国内精品欧美久久精品| 偷窥少妇久久久久久久久| 久久婷婷久久一区二区三区| 少妇被又大又粗又爽毛片久久黑人 | 欧美国产成人久久精品| 精品精品国产自在久久高清| 99久久精品免费看国产一区二区三区 | 999久久久国产精品| 色综合久久无码五十路人妻| 香蕉久久影院| 91久久九九无码成人网站| 国产精品一区二区久久精品| 热re99久久6国产精品免费| 色播久久人人爽人人爽人人片aV| 久久线看观看精品香蕉国产| 精品国产乱码久久久久久1区2区| 久久精品国产色蜜蜜麻豆| 久久久国产视频| 人妻丰满?V无码久久不卡| 久久久久国产| 人妻中文久久久久| 中文字幕无码久久人妻| 久久国产AVJUST麻豆| 一级女性全黄久久生活片免费| 久久精品国产亚洲Aⅴ蜜臀色欲| 日韩欧美亚洲综合久久影院d3| 日韩精品久久久肉伦网站| 欧美黑人激情性久久| 日本久久久久亚洲中字幕| 国内精品久久久久久99| 日韩一区二区久久久久久|