Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
Avoid using the Sleepfunction to get greater timer precision in real-time threads. Instead, 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 OS. By generating a system tick every millisecond, Windows Mobile enables an application to sleep for approximately 1 millisecond when it invokes the Sleepfunction with a dwMillisecondsparameter value of 1. A thread can sleep for longer than a millisecond, depending on its priority in relation to other active threads and whether any interrup service routines (ISRs) are running. At a minimum, a Sleep(1)calls sleep for 1. zmilliseconds, where zis the remaining time, less than a millisecond, until the next tick when the thread calls Sleep. A return from a Sleepcall also depends upon your priority in relation to the other threads in the system. The APIs set the minimum time that a thread waits or sleeps.
The only kernel variables needed to determine whether a reschedule should occur is dwReschedTime. The following code example shows how to schedule a timer interrupt:
Copy Code | |
---|---|
if ((int) (CurMSec – dwReschedTime) >= 0) return SYSINTR_RESCHED; else return SYSINTR_NOP; |