Boost C++ Libraries: Ticket #7719: C++11 steady_clock is not monotonic on Win32 & OSX https://svn.boost.org/trac10/ticket/7719 <p> Boost 1.52 defers to different OS specific calls for implementation of the std::chrono::steady_clock monotonic interface. There are supposed to be two characteristics: 1) monotonic, 2) independent of wall time. The current Boost implementation only achieves the latter. </p> <p> Issue raised from Stackoverflow: stackoverflow.com/q/13478093/175849 </p> <p> Per platform discussion: </p> <p> <strong>POSIX</strong>: defers to <code>clock_gettime (CLOCK_MONOTONIC)</code>. Generally sufficient excepting peculiarities of hyper-threading. </p> <p> <strong>OSX</strong>: defers to <code>mach_absolute_time()</code> which is implemented by <code>RDTSC</code> which is only monotonic on the same core. </p> <p> Apple recommend per their documentation to use <code>clock_get_time(SYSTEM_CLOCK)</code> as a monotonic source. References: </p> <p> www.opensource.apple.com/source/xnu/xnu-1486.2.11/osfmk/man/clock_get_time.html </p> <p> stackoverflow.com/q/11680461/175849 </p> <p> An important caveat is that the clock is not monotonic if <code>clock_set_time()</code> is called. </p> <p> <strong>Win32</strong>: defers to <code>QueryPerformanceCounter()</code> which on many platforms is not monotonic due to dependency on <code>RDTSC</code> as a direct source or interpolation of times from more reliable sources such as HPET, RTC, or PC AT. </p> <p> Microsoft in MSVC2012 implement <code>std::chrono</code> using <code>_Xtime_get_ticks()</code> which defers to <code>GetSystemTimeAsFileTime()</code> as discussed here (in Japanese): </p> <p> gist.github.com/3763854 </p> <p> This however is wall time and subject to clock changes, a more suitable source would be <code>GetTick64Count()</code> which requires Vista+, the alternative <code>GetTickCount()</code> wraps after 49.7 days. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7719 Trac 1.4.3 viboes Sun, 25 Nov 2012 08:40:43 GMT status changed https://svn.boost.org/trac10/ticket/7719#comment:1 https://svn.boost.org/trac10/ticket/7719#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> A steady clock is not necessarily a monotonic clock. N3128 (<a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3128.html"><span class="icon">​</span>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3128.html</a>) is the proposal that removed monotonic clocks and added steady clocks and includes the rationale: </p> <pre class="wiki"> The implementation of the timeout definition necessarily depends on a steady clock, one that cannot be adjusted. A monotonic clock is not sufficient. While one could be implicit in the standard, below we make one explicit. Given a steady clock, the monotonic clock seems to be of marginal utility, and we replace the monotonic clock with the steady clock. </pre><p> Please, let me know if there is something in the documentation that say something that doesn't conforms to the C++11 standard. </p> Ticket fnjordy@… Sun, 25 Nov 2012 15:09:35 GMT <link>https://svn.boost.org/trac10/ticket/7719#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7719#comment:2</guid> <description> <p> Of reference the Boost documentation defines <code>is_steady()</code> with the C++11 definition of <code>is_monotonic()</code>, MSDN provides the following: </p> <blockquote> <p> A clock is <em>monotonic</em> if the value that is returned by a first call to <code>now()</code> is always less than or equal to the value that is returned by a subsequent call to <code>now()</code>. </p> </blockquote> <blockquote> <p> A clock is <em>steady</em> if it is monotonic and if the time between clock ticks is constant. </p> </blockquote> <p> msdn.microsoft.com/en-us/library/hh874790.aspx </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 28 Nov 2012 11:06:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7719#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7719#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7719#comment:2" title="Comment 2">fnjordy@…</a>: </p> <blockquote class="citation"> <p> Of reference the Boost documentation defines <code>is_steady()</code> with the C++11 definition of <code>is_monotonic()</code>, MSDN provides the following: </p> </blockquote> <p> Please could you point me where in the Boost.Chrono documentation appears is_monotonic? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 28 Nov 2012 11:14:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7719#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7719#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7719#comment:3" title="Comment 3">viboes</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7719#comment:2" title="Comment 2">fnjordy@…</a>: </p> <blockquote class="citation"> <p> Of reference the Boost documentation defines <code>is_steady()</code> with the C++11 definition of <code>is_monotonic()</code>, MSDN provides the following: </p> </blockquote> <p> Please could you point me where in the Boost.Chrono documentation appears is_monotonic? </p> </blockquote> <p> Oh, I got it. The doc don't use is_monotonic but the definition corresponds. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 28 Nov 2012 11:19:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7719#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7719#comment:5</guid> <description> <p> Your proposal are not steady (following the C++11 standard definition), except maybe <a class="missing wiki">GetTickCount</a>(). The problem with <a class="missing wiki">GetTickCount</a>() is that it is not enough long. Do you have a suggestion? </p> <p> Please, could you give me the link to the stack overflow discussion? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 08 Dec 2012 16:11:28 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7719#comment:6 https://svn.boost.org/trac10/ticket/7719#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket viboes Sat, 08 Dec 2012 16:11:45 GMT milestone deleted https://svn.boost.org/trac10/ticket/7719#comment:7 https://svn.boost.org/trac10/ticket/7719#comment:7 <ul> <li><strong>milestone</strong> <span class="trac-field-deleted">To Be Determined</span> </li> </ul> Ticket