首页 > 代码库 > Event
Event
// Event.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> #include <assert.h> DWORD WINAPI ThreadProc1(LPVOID lpThreadParameter); DWORD WINAPI ThreadProc2(LPVOID lpThreadParameter); int main() { HANDLE hEvent = CreateEventA(0, 1, 0, "Event0"); // 手动 无信号 if (!hEvent) { assert(0); } SetEvent(hEvent); // 有信号 HANDLE hThread[2]{}; hThread[0] = CreateThread(0, 0, ThreadProc1, 0, 0, 0); hThread[1] = CreateThread(0, 0, ThreadProc2, 0, 0, 0); WaitForMultipleObjects(2, hThread, TRUE, INFINITE); CloseHandle(hThread[0]); CloseHandle(hThread[1]); system("pause"); return 0; } DWORD WINAPI ThreadProc1(LPVOID lpThreadParameter) { HANDLE hEvent = OpenEventA(EVENT_ALL_ACCESS, 0, "Event0"); // 没影响 if (!hEvent) { assert(0); } WaitForSingleObject(hEvent, INFINITE); // 因为是手动的,所以还是有信号 ResetEvent(hEvent); // 无信号 return 0; } DWORD WINAPI ThreadProc2(LPVOID lpThreadParameter) { HANDLE hEvent = OpenEventA(EVENT_ALL_ACCESS, 0, "Event0"); if (!hEvent) { assert(0); } WaitForSingleObject(hEvent, INFINITE); return 0; }
Event
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。