// Events.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
#include <WinSock2.h>
#include <Windows.h> using namespace std; HANDLE g_Events[] = {}; UINT32 _stdcall CallBack(LPVOID lParam);
int _tmain(int argc, _TCHAR* argv[])
{
//HANDLE ThreadHandle = CreateThread();
//内核对象,返回值为句柄,并且配有安全属性
//一般对象,返回值为句柄
//自动 未授信 匿名
g_Events[] = CreateEvent(NULL,TRUE,FALSE,NULL);
g_Events[] = CreateEvent(NULL,TRUE,FALSE,NULL); HANDLE ThreadHandle = CreateThread(NULL,,(LPTHREAD_START_ROUTINE)CallBack,NULL,,NULL); int i = ;
for(i=;i<;i++)
{
printf("Main()\r\n");
if(i==)
{
SetEvent(g_Events[]); //NO-->YES
//Sleep(1); WaitForSingleObject(g_Events[],INFINITE);
//ResetEvent(g_Events[0]); //YES-->NO
}
}
Sleep(INFINITE);
return ;
} UINT32 _stdcall CallBack(LPVOID lParam)
{
int i = ;
//等待事件A授信
WaitForSingleObject(g_Events[],INFINITE); printf("SubMain()\r\n");
//ResetEvent(g_Events[0]);
WaitForSingleObject(g_Events[],INFINITE);
SetEvent(g_Events[]);
printf("SubMain()\r\n");
return ;
}