c++ vs2008 多线程编程的样例

#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
HANDLE g_hEvent;
DWORD WINAPI Fun(LPVOID lpParamter)
{

while(1) {
WaitForSingleObject(g_hEvent, INFINITE);
cout<<"Fun display!"<<endl;
Sleep(1000);
SetEvent(g_hEvent);
}
}

int main()
{
HANDLE hThread = CreateThread(NULL, 0, Fun, NULL, 0, NULL);

HANDLE g_hEvent = CreateEvent(NULL, false, true, NULL);


CloseHandle(hThread);
while(1) {
WaitForSingleObject(g_hEvent, INFINITE);
cout<<"main display!"<<endl;
Sleep(2000);
SetEvent(g_hEvent);
}
return 0;
}

原文地址:https://www.cnblogs.com/renly/p/3020413.html