System Timer Considerations (Windows CE 5.0)

Send Feedback

Avoid using the Sleep API in real-time threads, if you need greater timer precision. Instead, you should use a timer mechanism that is based on an interrupt or the multimedia timers. The system timer generates system ticks at a fixed rate of one tick per millisecond, which is the rate at which a timer interrupt is generated and serviced by the operating system (OS). By generating a system tick every millisecond, Windows CE enables an application to sleep for approximately 1 millisecond when it invokes the Sleep function with a dwMilliseconds parameter value of 1. A thread may sleep for longer than a millisecond depending on its priority in relation to other active threads and whether any ISRs are running. At a minimum, a Sleep(1) call will sleep for 1.z milliseconds, where z is the remaining time, less than a millisecond, until the next tick when the thread calls Sleep. A return from a Sleep call also depends upon your priority in relation to the other threads in the system. The APIs set the minimal time that a thread will wait or sleep.

The only kernel variables needed to determine if a reschedule should occur is dwReschedTime. Use the following logic on timer interrupt.

if ((int) (CurMSec – dwReschedTime) >= 0)
return SYSINTR_RESCHED;
else
    return SYSINTR_NOP;

See Also

Real-Time Performance Considerations

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.