开启线程CreatThread函数的使用,主线程与工作线程的交互。
开启线程CreatThread函数的使用,主线程与工作线程的交互
//线程函数
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
for (int i=0;i<20;i++)
{
printf("I'm in thread,count=%d\n",i);
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwThreadId;
HANDLE hThread = ::CreateThread(NULL, 0, ThreadProc,NULL, 0, &dwThreadId);
if (hThread == NULL)
{
printf("createThread failed...");
return -1;
}
//等待线程结束
::WaitForSingleObject(hThread, INFINITE);
printf("thread finished...");
::CloseHandle(hThread);
return 0;
}
页:
[1]