1. 基本函数
HANDLE CreateEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset , BOOL bInitialState , LPCWSTR lpName);
HANDLE OpenEvent(DWORD dwDesiredAccess , BOOL bInheritHandle ,
LPCWSTR lpName);
BOOL SetEvent(HANDLE hEvent);
BOOL Resetevent(HANDLE hEvent); 设置受信和未受信
#include <stdio.h>
#include <windows.h>
#include <process.h>
HANDLE g_hEvent;
UINT WINAPI ThreadProc(LPVOID lpParam){
WaitForSingleObject(g_hEvent,INFINITE);
printf("Child thread is running\n\n");
Sleep(5 * 1000);
return 0;
}
int _cdecl main(int argc,char *argv[]){
HANDLE hThread;
UINT uId;
g_hEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
hThread = (HANDLE)_beginthreadex(NULL,0,ThreadProc,NULL,0,&uId);
printf("\nEnter a char\n");
getchar();
SetEvent(g_hEvent);
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
CloseHandle(g_hEvent);
return 0;
}