可等待计时器添加APC测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了可等待计时器添加APC测试相关的知识,希望对你有一定的参考价值。
unsigned APIENTRY ThreadProc(void *p)
{
WaitForSingleObject(g_hWaitableTimer, INFINITE);
MessageBox(NULL, _T("线程开始启动"), _T("HELLO"), MB_OK);
return 0;
}
void APIENTRY ApcCompletionRoutine(PVOID pParm, DWORD dwTimerLowValue, DWORD dwTimeHighValue)
{
MessageBox(NULL, _T("ApcCompletionRoutine开始启动"), _T("HELLO"), MB_OK);
return;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: 在此放置代码。
unsigned ThreadId;
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadProc, NULL, NULL, &ThreadId);
g_hWaitableTimer = CreateWaitableTimer(NULL, FALSE, NULL);
LARGE_INTEGER liStartTime;
liStartTime.QuadPart = -(5 * 1000 * 1000 * 10);
SetWaitableTimer(g_hWaitableTimer, &liStartTime, 0, ApcCompletionRoutine, NULL, FALSE);
SleepEx(INFINITE, TRUE); // 关键
CloseHandle(hThread);
CloseHandle(g_hWaitableTimer);
MSG msg;
HACCEL hAccelTable;
// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WAITABLETIMERTEST, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WAITABLETIMERTEST));
// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
以上是关于可等待计时器添加APC测试的主要内容,如果未能解决你的问题,请参考以下文章
JUC并发编程 共享模式之工具 JUC CountdownLatch(倒计时锁) -- CountdownLatch应用(等待多个线程准备完毕( 可以覆盖上次的打印内)等待多个远程调用结束)(代码片段