• <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>

            C++ Programmer's Cookbook

            {C++ 基礎} {C++ 高級} {C#界面,C++核心算法} {設計模式} {C#基礎}

            C++多線程(五)

             
            多線程之等待函數
            一 等待函數

            1)函數列舉

            Wait function Description
            MsgWaitForMultipleObjects Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses. The objects can include input event objects.
            MsgWaitForMultipleObjectsEx Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses. The array of objects can include input event objects.
            RegisterWaitForSingleObject Directs a wait thread in the thread pool to wait on the object.
            SignalObjectAndWait Atomically signals one object and waits on another object.
            UnregisterWait Cancels a registered wait operation.
            UnregisterWaitEx Cancels a registered wait operation.
            WaitForMultipleObjects Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses.
            WaitForMultipleObjectsEx Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.
            WaitForSingleObject Waits until the specified object is in the signaled state or the time-out interval elapses.
            WaitForSingleObjectEx Waits until the specified object is in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.
            WaitOrTimerCallback An application-defined function that serves as the starting address for a timer callback or a registered wait callback.


            Waitable-timer function Description
            CancelWaitableTimer Sets the specified waitable timer to the inactive state.
            CreateWaitableTimer Creates or opens a waitable timer object.
            CreateWaitableTimerEx Creates or opens a waitable timer object and returns a handle to the object.
            OpenWaitableTimer Opens an existing named waitable timer object.
            SetWaitableTimer Activates the specified waitable timer.
            TimerAPCProc Application-defined timer completion routine used with the SetWaitableTimer function.


            2)簡單說明WaitForSingleObject

            DWORD WaitForSingleObject(HANDLE hObject,DWORD dwMilliseconds);

            參數hObject:要等待的內核對象的句柄。
            參數dwMilliseconds: 設置的等待超時的時間,以毫秒為單位。可以設置為INGINIT。     
                                                 順便說一下,INFINITE已經定義為0xFFFFFFFF(或-1)。當然,傳遞INFINITE有些危險。如果對象永遠不變為已
                                                 通知狀態,那么調用線程永遠不會被喚醒,它將永遠處于死鎖狀態。
            返回值:WAIT_OBJECT_0表示要等待的對象已經變為已通知的狀態。
                             WAIT_TIMEOUT表示設置的時間超時。
                             WAIT_FAILED表示失敗,可能是傳入的handle不正確或其他的問題。

            DWORD dw = WaitForSingleObject(hProcess, 5000);
            switch(dw)
            {
               
            case WAIT_OBJECT_0:
                  
            // The process terminated.
                  break;

               
            case WAIT_TIMEOUT:
                  
            // The process did not terminate within 5000 milliseconds.
                  break;

               
            case WAIT_FAILED:
                  
            // Bad call to function (invalid handle?)
                  break;
            }

            3)簡單說明WaitForMultipleObjects

            DWORD WaitForMultipleObjects(DWORD dwCount,CONST HANDLE* phObjects,BOOL fWaitAll,DWORD dwMilliseconds);

            參數dwCout:需要等待的內核對象的數量。
            參數phObjects:需要等待的內核對象的是數組的指針。
            參數fWaitAll:表示是否需要等待所有的內核對象。
            參數dwMilliseconds:設置等待超時的時間。(同上函數)

            返回值:WAIT_FAILED和WAIT_TIMEOUT同上函數。
             如果為fWaitAll參數傳遞TRUE,同時所有對象均變為已通知狀態,那么返回值是WAIT_OBJECT_0。如果為fWaitAll傳遞FALSE       ,那么一旦任何一個對象變為已通知狀態,該函數便返回。在這種情況下,你可能想要知道哪個對象變為已通知狀態。返回值是WAIT_OBJECT_0與(WAIT_OBJECT_0+dwCount- 1)之間的一個值。

            HANDLE h[3];
            h[
            0= hProcess1;
            h[
            1= hProcess2;
            h[
            2= hProcess3;
            DWORD dw 
            = WaitForMultipleObjects(3, h, FALSE, 5000);
            switch(dw) 
            {
               
            case WAIT_FAILED:
                  
            // Bad call to function (invalid handle?)
                  break;

               
            case WAIT_TIMEOUT:
                  
            // None of the objects became signaled within 5000 milliseconds.
                  break;

               
            case WAIT_OBJECT_0 + 0:
                  
            // The process identified by h[0] (hProcess1) terminated.
                  break;

               
            case WAIT_OBJECT_0 + 1:
                  
            // The process identified by h[1] (hProcess2) terminated.
                  break;

               
            case WAIT_OBJECT_0 + 2:
                  
            // The process identified by h[2] (hProcess3) terminated.
                  break;
            }


            二 參考msdn和windows核心編程。

            posted on 2007-07-28 10:36 夢在天涯 閱讀(6279) 評論(1)  編輯 收藏 引用 所屬分類: CPlusPlus

            評論

            # re: C++多線程(五) 2009-06-10 11:16 aniki

            關注中  回復  更多評論   

            公告

            EMail:itech001#126.com

            導航

            統計

            • 隨筆 - 461
            • 文章 - 4
            • 評論 - 746
            • 引用 - 0

            常用鏈接

            隨筆分類

            隨筆檔案

            收藏夾

            Blogs

            c#(csharp)

            C++(cpp)

            Enlish

            Forums(bbs)

            My self

            Often go

            Useful Webs

            Xml/Uml/html

            搜索

            •  

            積分與排名

            • 積分 - 1807691
            • 排名 - 5

            最新評論

            閱讀排行榜

            国产精品九九九久久九九| 婷婷久久香蕉五月综合加勒比| 久久国产色AV免费观看| 国产精品伊人久久伊人电影| 亚洲国产成人久久一区久久| 久久免费线看线看| 久久久精品2019免费观看| 久久被窝电影亚洲爽爽爽| 亚洲精品无码久久久影院相关影片| 久久99精品久久久久子伦| 成人午夜精品无码区久久| 亚洲精品久久久www| 国产精品久久午夜夜伦鲁鲁| 久久精品国产一区二区三区不卡| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 日本高清无卡码一区二区久久| 国产亚洲综合久久系列| 久久精品国产99久久丝袜 | 久久精品国产亚洲网站| 色天使久久综合网天天| 久久中文娱乐网| 人人狠狠综合久久88成人| 中文字幕乱码人妻无码久久| 一本大道加勒比久久综合| 7国产欧美日韩综合天堂中文久久久久 | 热re99久久精品国99热| 午夜精品久久久久成人| 久久国产免费直播| 一级做a爰片久久毛片人呢| 无码精品久久久天天影视 | 亚洲精品美女久久久久99小说| 99久久久精品| 久久精品国产久精国产思思| 一本色综合网久久| 久久精品国产亚洲av麻豆蜜芽 | 久久久久久九九99精品| 免费久久人人爽人人爽av| 久久久无码精品亚洲日韩蜜臀浪潮| 欧美日韩精品久久久免费观看| 少妇久久久久久被弄到高潮| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 |