![]() While ((ft0.dwHighDateTime = ft1.dwHighDateTime) & (ft0.dwLowDateTime = ft1.dwLowDateTime)) performance counter value for that time. Spin waiting for a change in system time. Void simplistic_synchronize(reference_point& ref_point) Std::cout #include #include struct reference_point And what about GetSystemTimeAsFileTime with its 100 nanosecond resolution? Let's start out by performing a little experiment: try repeatedly retrieving the system time, formatting it, and outputting it to the screen (see Figure 1).įigure 1 Retrieving and Outputting System Time #include #include #include int main(int argc, char* argv) You might think this would be easy with the GetSystemTime API, which returns a SYSTEMTIME structure containing a wMilliseconds field documented in MSDN as storing the current millisecond. I will concentrate here on why it's difficult to obtain the system time with a resolution greater than 10 milliseconds. The majority discussed either how to obtain the system time with a higher resolution than 10 milliseconds or how to cause a thread to sleep for less than 10 milliseconds. When I recently did an Internet search for "Windows NT millisecond time resolution," I got well over 400 hits. ![]() For the parameter types and usage of the Win32® APIs referenced in the article, refer to the MSDN Library/Platform SDK documentation. During the course of this article, though, I will frequently refer to the Windows NT® family of operating systems (Windows NT 4.0, Windows 2000, or Windows XP) rather than to a specific version. The source code for these files was written and tested using Visual C++® 7.1 and Windows® XP Professional. A sample implementation is available for download at the link at the top of this article. In the following article, I'll explain this system time resolution limit, the steps needed to overcome it, and some of the common pitfalls. I also needed to relate these events to absolute time, but noticed that the actual resolution of the system time was no more granular than 10 milliseconds. Why would you be interested in obtaining the system time with a resolution below one millisecond? In the course of my work, I found it necessary to be able to determine the sequence of events originating from different threads of execution in my process. This article shows one possible way of overcoming limitations inherent in this approach. But using performance counters is a technique that presents its own problems. For example, what if you want to be able to contact a thread or perform some other task at intervals more frequent than 10 milliseconds? Suggested ways of achieving better resolution include using performance counters in conjunction with the sytem time to calculate smaller time increments. At times, such as when you need to timetag frequent events, it is desirable to achieve a higher resolution. The timestamps that you can obtain from Windows NT are limited to a maximum resolution of 10 or 15 milliseconds, depending on the underlying hardware. This article assumes you're familiar with C++ and the Win32 API Implement a Continuously Updating, High-Resolution Time Provider for WindowsĬode download available at: HighResolutionTimer.exe(404 KB)
0 Comments
Leave a Reply. |