Win32多線程(二)

Win32 API多線程函數

1HANDLE CreateThread(

             LPSECURITY_ATTRIBUTES lpThreadAttributes,

              // pointer to security attributes

             DWORD dwStackSize,

              // initial thread stack size

             LPTHREAD_START_ROUTINE lpStartAddress,

              // pointer to thread function

             LPVOID lpParameter,

              // argument for new thread

             DWORD dwCreationFlags,

              // creation flags

             LPDWORD lpThreadId

              // pointer to receive thread ID

);

該函數在進程空間裏創建一個新線程,並返回線程句柄

 

2DWORD SuspendThread(
              HANDLE hThread   // handle to the thread
);

該函數用於掛起指定線程

 

3DWORD ResumeThread(
              HANDLE hThread   // identifies thread to restart
);

該函數用於結束線程的掛機狀態,執行線程

 

4VOID ExitThread(
              DWORD dwExitCode   // exit code for this thread
);

該函數線程終止自身的執行,主要用在線程的執行函數中被調用。

 

5BOOL TerminateThread(
              HANDLE hThread,                // handle to the thread
              DWORD dwExitCode            // exit code for the thread
);

一般情況下,線程運行結束後,線程函數正常返回,但應用程序也可以調用該函數強行終止某一線程。

 

6BOOL PostThreadMessage(
              DWORD idThread,  // thread identifier
              UINT Msg,         // message to post
              WPARAM wParam,                // first message parameter
              LPARAM lParam    // second message parameter
);

該函數將一條消息放入到指定線程的消息隊列中,並且不等到消息被該線程處理就返回。如果該線程沒有創建消息循環,則函數執行失敗。

 

7DWORD WaitForSingleObject(
  HANDLE hHandle,        // handle to object to wait for
  DWORD dwMilliseconds   // time-out interval in milliseconds
);

該函數使調用它的線程暫停,等待一個特定對象,當對象處於信號狀態或者等待時間到才返回。

 

8DWORD WaitForMultipleObjects(
  DWORD nCount,                       // number of handles in the handle array
  CONST HANDLE *lpHandles,             // pointer to the object-handle array
  BOOL fWaitAll,                           // wait flag
  DWORD dwMilliseconds                 // time-out interval in milliseconds
);

該函數使調用它的線程暫停,等待一組對象(線程),當一個或所有(fWaitAll決定)對象處於信號狀態或者等待時間到才返回。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章