-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestAPC.cpp
57 lines (44 loc) · 1.22 KB
/
TestAPC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// TestACP.cpp --- Test for QueueUserAPC and threads
#include <windows.h>
#include <process.h> // for _beginthreadex
#include <stdio.h> // for printf
BOOL g_bTerminateAll = FALSE;
unsigned __stdcall thread_proc(void *)
{
while (!g_bTerminateAll)
{
printf("thread_proc: sleep\n");
SleepEx(INFINITE, TRUE);
printf("thread_proc: awake\n");
}
return 0;
}
VOID NTAPI DoUserAPC(ULONG_PTR Parameter)
{
printf("DoUserAPC(%p)\n", Parameter);
}
VOID NTAPI TerminateAPC(ULONG_PTR Parameter)
{
printf("TerminateAPC(%p)\n", Parameter);
g_bTerminateAll = TRUE;
}
int main(void)
{
unsigned tid;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, thread_proc, NULL, 0, &tid);
printf("main: sleep\n");
Sleep(3 * 1000);
printf("main: awake\n");
QueueUserAPC(DoUserAPC, hThread, 0);
printf("main: sleep\n");
Sleep(3 * 1000);
printf("main: awake\n");
QueueUserAPC(DoUserAPC, hThread, 1);
printf("main: sleep\n");
Sleep(3 * 1000);
printf("main: awake\n");
QueueUserAPC(TerminateAPC, hThread, 2);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
return 0;
}