Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative to Sleep()

Status
Not open for further replies.

sweep123

Technical User
May 1, 2003
185
GB
My PC has a clock resolution of 10ms. (from a benchmark utility program).

I need to make avaliable some data for a period of 50ms, so was thinking of using CreatWaitableTimer;

i.e. Wait (50 /* 50ms */);
bool Wait(int period)
{
HANDLE hTimer = NULL;
LARGE_INTEGER timeDue;
hTimer = CreateWaitableTimer(NULL, TRUE, "WAIT50MS");

SetWaitable(hTimer, &timeDue, 0, NULL, NULL, 0);

WaitForSingleObject(hTimer, INIFITE);

return true;
}

I understand Sleep(50); would be OK for most of the time but could fail when Windows schedules some other activity.

How god would the alternative above be?

I did some timing tests, but am I missing anything?

Sweep.
 
have you had any craches of Sleep before? For example I had not.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Are you saying - stick with Sleep()?

Sweep
 
yes

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top