创建线程的时候可以选择立即激活或者暂时挂起,而此函数就是用于激活挂起的线程。
Example:
#include "stdafx.h"
#include "windows.h"
#include "process.h"
#include "iostream"
using namespace std;
unsigned int __stdcall ThreadProc1(LPVOID lParam)
{
cout << "This is the first thread!\n";
return 0;
}
unsigned int __stdcall ThreadProc2(LPVOID lParam)
{
cout << "This is the second thread!\n";
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hThread[2];
hThread[0] = (HANDLE)_beginthreadex(NULL,0,ThreadProc1,NULL,0,NULL); //thread active when create
hThread[1] = (HANDLE)_beginthreadex(NULL,0,ThreadProc2,NULL,CREATE_SUSPENDED,NULL); // thread suspend when create
WaitForSingleObject(hThread[0],INFINITE);
ResumeThread(hThread[1]); //start suspend thread
WaitForSingleObject(hThread[1],INFINITE);
CloseHandle(hThread[0]);
CloseHandle(hThread[1]);
return 0;
}