High-Precision Timing Under Windows, Windows NT, & Windows 95Last reviewed: May 3, 1996Article ID: Q148404 |
The information in this article applies to:
SUMMARYWindows 3.1 developers who require high precision timers can use the multimedia timers, which are accurate to 10 milliseconds (ms) in most cases. However, in the multithreaded environments of Windows NT and Windows 95, the resolution and accuracy of the multimedia timers may often be reduced due to the preemptive nature of the operating systems.
MORE INFORMATIONIn Windows 3.1, multimedia timers are serviced by an interrupt service routine (ISR) which is tied to the computer's clock. When a tick on the clock occurs, Windows suspends the running program and services the tick. Should your application use multimedia timers (by using TimeSetEvent() and any of the CALLBACK flags), Windows executes your callback function before returning control to the suspended program. Servicing your callback function during the hardware timer tick provides high precision timing because your callback is being executed within the timer interrupt, and interrupt routines cannot, themselves, be interrupted. The multithreaded environments of Windows NT and Windows 95 employ CPU scheduling techniques to improve processor utilization and smooth multitasking. The portions of code, called threads, within the system are organized into queues and assigned priorities. Threads of code required by the operating system are assigned high priorities. The thread scheduler allows a thread a predetermined amount of execution time (quantum). Then it evicts the thread from the processor until all threads at the specific priority level have been serviced. The process continues at the next, lower, priority level. The timer-servicing thread, like applications, is subject to CPU scheduling and eviction regardless of the thread priority. Given that the number of threads ready for execution changes frequently, the period between timer thread executions can vary dramatically. For example, say five time-critical threads are ready for execution, and the quantum is q milliseconds. If the timer thread is fifth, four threads execute before the timer thread is executed; q milliseconds x 4. This means that if q is 25 milliseconds, 100 milliseconds will have elapsed before the fifth thread is executed. Boosting the priority of the thread that created the timer risks introducing instability in the system by starving the time-sensitive, system-critical threads.
|
Additional reference words: 4.00 3.50 multimedia resolution flat generic
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |