SleepEx problem

N

NewToCPP

SleepEx suspends the current thread until the specified condition is
met. I expected the execution to resume when occurs the timeout happens
in my following example.

At the expiry of the timer it is calling "lpFnToCompletionRoutine" as
expected, but it is not printing Count in the while loop. Can anyone
explain why?




static void APIENTRY lpFnToCompletionRoutine (LPVOID lpCount,
DWORD dwTimerLowValue,
DWORD dwTimerHighValue)
{
*(LPWORD) lpCount = *(LPWORD) lpCount + 1;

}

void OmciAdapter::adapterMain()
{

/* STEPS to DO: */

//1. set the timer for every 100 milli secs to check for any OMCI
timeouts

HANDLE hTimer;
LARGE_INTEGER DueTime;
DWORD Count = 0;
const int unitsPerSecond=10*1000*1000; // 100 nano seconds


DueTime.QuadPart = -(10000 * 10000);
hTimer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer");

if (NULL == hTimer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return;
}

printf("Waiting for 10 seconds...\n");

// Set a timer to wait for 10 seconds.
if (!SetWaitableTimer(hTimer, &DueTime, 10000,
lpFnToCompletionRoutine, &Count, FALSE))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return;
}

while (1)
{
printf ("Count = %d \n", Count);


SleepEx(INFINITE, TRUE);
}



.................

.................

.................

.................


}
 
V

Victor Bazarov

NewToCPP said:
SleepEx suspends the current thread until the specified condition is
met. I expected the execution to resume when occurs the timeout
happens in my following example.

At the expiry of the timer it is calling "lpFnToCompletionRoutine" as
expected, but it is not printing Count in the while loop. Can anyone
explain why?
[...]

Somebody in the newsgroup that deals with those functions and their
semantics should be able to. I can only speculate that your timers
are not running in a separate thread, and as such are probably just
as well suspended by your SleepEx. But your question is OS-specific
and as such is off-topic here. The list of suggested newsgroups is
in the FAQ.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top