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决定)对象处于信号状态或者等待时间到才返回。

你可能感兴趣的:(Win32多线程(二))