关于QueueUserAPC的问题
// test11.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <process.h>
volatile bool a = false;
HANDLE h1, h2;
HANDLE h0;
HANDLE hArr[5];
unsigned __stdcall fun( void *p )
{
int n = (int)p;
::WaitForMultipleObjects(2, hArr + (n-1), true, INFINITE);
printf("%d\n", n);
return 0;
}
VOID WINAPI WFME(ULONG_PTR dwData) {
// This function intentionally left blank
}
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hand[2];
h0 = CreateSemaphore(NULL, 1, 1, NULL);
h1 = ::CreateEvent(NULL, false, false, NULL);
h2 = ::CreateEvent(NULL, false, false, NULL);
hArr[0] = h1;
hArr[1] = h0;
hArr[2] = h2;
hand[0] = (HANDLE)_beginthreadex(NULL, 0, fun, (VOID*)1, 0, 0);
hand[1] = (HANDLE)_beginthreadex(NULL, 0, fun, (VOID*)2, 0, 0);
if (MessageBox(NULL, "fwef", "fwef", MB_YESNO) == IDYES)
::SetEvent(h1);
else
::SetEvent(h2);
::WaitForMultipleObjects(2, hand, false, INFINITE);
QueueUserAPC(WFME, hand[0], 0);
QueueUserAPC(WFME, hand[1], 0);
::WaitForMultipleObjects(2, hand, true, INFINITE);
printf("OK\n");
CloseHandle(h1);
CloseHandle(h2);
CloseHandle(hand[0]);
system("pause");
return 0;
}
我想让两个线程中的一个返回后就在线程队列中加入函数 让另一个不再等待 可是不行 为什么啊