Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ULONG WINAPI workThread(HANDLE hIOCP)
- {
- ULONG dwBytes;
- ULONG_PTR Key;
- OVERLAPPED* Irp;
- while(GetQueuedCompletionStatus(hIOCP, &dwBytes, &Key, &Irp, INFINITE))
- {
- DbgPrint("%x.%u>%p %p %x\n", GetCurrentThreadId(), GetTickCount(), Key, Irp, dwBytes);
- if (Irp)
- {
- delete Irp;
- ULONG64 t = GetTickCount64() + 4000;// wait 4 sec
- do
- {
- } while (GetTickCount64() < t);
- }
- else{
- break;
- }
- }
- return 0;
- }
- ULONG StartThreads(HANDLE* phThreads, ULONG n, HANDLE hIOCP)
- {
- ULONG m = 0;
- do
- {
- if (HANDLE hThread = CreateThread(0, 0x1000, workThread, hIOCP, 0, 0))
- {
- m++;
- *phThreads++ = hThread;
- }
- } while (--n);
- return m;
- }
- void testIOP()
- {
- HANDLE hThreads[2], *phThreads;
- if (HANDLE hIOCP = CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, 1))
- {
- int i = 4;
- do
- {
- if (OVERLAPPED* Irp = new OVERLAPPED)
- {
- if (!PostQueuedCompletionStatus(hIOCP, i, i, Irp))
- {
- delete Irp;
- }
- }
- } while (--i);
- PostQueuedCompletionStatus(hIOCP, 1, 1, 0);
- PostQueuedCompletionStatus(hIOCP, 2, 2, 0);
- if (ULONG m = StartThreads(hThreads, RTL_NUMBER_OF(hThreads), hIOCP))
- {
- ULONGLONG t = GetTickCount64();
- WaitForMultipleObjects(m, hThreads, true, INFINITE);
- t = GetTickCount64() - t;
- DbgPrint("%I64u.%u\n", t / 1000, t % 1000);
- phThreads = hThreads + m;
- do
- {
- CloseHandle(*--phThreads);
- } while (--m);
- }
- CloseHandle(hIOCP);
- }
- }
- f1c.24551937>0000000000000004 000001F939E3E290 4
- f1c.24555937>0000000000000003 000001F939E3E150 3
- f1c.24559937>0000000000000002 000001F939E36460 2
- f1c.24563937>0000000000000001 000001F939E3A6D0 1
- f1c.24567937>0000000000000001 0000000000000000 1
- The thread 'Win64 Thread' (0xf1c) has exited with code 0 (0x0).
- e50.24567937>0000000000000002 0000000000000000 2
- The thread 'Win64 Thread' (0xe50) has exited with code 0 (0x0).
- 16.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement