Boost C++ Libraries: Ticket #8136: [windows] boost::this_thread::sleep_for() sleeps longer than it should in Windows https://svn.boost.org/trac10/ticket/8136 <p> Calling the this_thread::sleep_for() results in a sleep almost twice as long as desired. </p> <p> code: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/thread.hpp&gt; int main(int argc, char * argv[]) { boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now(); boost::this_thread::sleep_for(boost::chrono::seconds(1)); boost::chrono::system_clock::time_point end = boost::chrono::system_clock::now(); std::cout &lt;&lt; (boost::chrono::duration_cast&lt;boost::chrono::microseconds&gt;(end - start)).count() &lt;&lt; std::endl; return 0; } </pre><p> When built in MS Windows 7 x64, the program outputs 2000114 </p> <p> The same code in linux x64 outputs 1000298 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8136 Trac 1.4.3 viboes Thu, 21 Feb 2013 18:23:46 GMT owner, status changed https://svn.boost.org/trac10/ticket/8136#comment:1 https://svn.boost.org/trac10/ticket/8136#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I have no access to a windows machine now. Could you do the test for 5 seconds? and 100ms? </p> Ticket Ondrej Siler <ondrej.siler@…> Thu, 21 Feb 2013 21:18:32 GMT <link>https://svn.boost.org/trac10/ticket/8136#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:2</guid> <description> <p> Same behaviour - for 5 seconds sleeps 10 secs, for 100ms sleeps 200ms. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 03 Mar 2013 14:08:37 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/8136#comment:3 https://svn.boost.org/trac10/ticket/8136#comment:3 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.54.0</span> </li> </ul> <p> Please, could you check if the following update works for you? </p> <p> Committed in trunk revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/83282" title="Thread: take care of #8136">[83282]</a>. </p> Ticket Ondrej Siler <ondrej.siler@…> Mon, 04 Mar 2013 15:28:02 GMT <link>https://svn.boost.org/trac10/ticket/8136#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:4</guid> <description> <p> I cannot link without BOOST_USE_WINDOWS_H defined. </p> <p> With BOOST_USE_WINDOWS_H defined, it works ok. </p> <p> Shouldn't be the test in thread/win32/thread_primitives.hpp:21 </p> <pre class="wiki">#if _WIN32_WINNT &gt;= 0x0600 </pre><p> instead of </p> <pre class="wiki">#if WINNT &gt;= 0x0600 </pre><p> MS Visual Studio (IDE) doesn't know WINNT, but is happy with _WIN32_WINNT </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 04 Mar 2013 17:48:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8136#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/8136#comment:4" title="Comment 4">Ondrej Siler &lt;ondrej.siler@…&gt;</a>: </p> <blockquote class="citation"> <p> I cannot link without BOOST_USE_WINDOWS_H defined. </p> <p> With BOOST_USE_WINDOWS_H defined, it works ok. </p> <p> Shouldn't be the test in thread/win32/thread_primitives.hpp:21 </p> <pre class="wiki">#if _WIN32_WINNT &gt;= 0x0600 </pre><p> instead of </p> <pre class="wiki">#if WINNT &gt;= 0x0600 </pre><p> MS Visual Studio (IDE) doesn't know WINNT, but is happy with _WIN32_WINNT </p> </blockquote> <p> I suspect that you are talking of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8070" title="#8070: Bugs: prefer GetTickCount64 over GetTickCount (closed: fixed)">#8070</a>, isn't it? </p> </description> <category>Ticket</category> </item> <item> <author>Ondrej Siler <ondrej.siler@…></author> <pubDate>Mon, 04 Mar 2013 19:17:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8136#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:6</guid> <description> <p> Yes, you are right. According to <a class="ext-link" href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724411%28v=vs.85%29.aspx"><span class="icon">​</span>MSDN</a>: "To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later." </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 09 Mar 2013 16:05:48 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8136#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:7</guid> <description> <p> Committed revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/83294" title="Thread: make use of _WIN32_WINNT instead of WINNT.">[83294]</a><a class="changeset" href="https://svn.boost.org/trac10/changeset/83318" title="Thread: try to fix double definition of GetTickCount64.">[83318]</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 23 Mar 2013 01:54:12 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8136#comment:8 https://svn.boost.org/trac10/ticket/8136#comment:8 <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">fixed</span> </li> </ul> <p> Committed revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/83525" title="Thread: merge from trunk. 1.54">[83525]</a>. </p> Ticket anonymous Sun, 14 Sep 2014 10:07:53 GMT <link>https://svn.boost.org/trac10/ticket/8136#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:9</guid> <description> <p> on boost 1.56 this bug is back. sleeping for 1000 microseconds sleeps for about 2,000 microseconds. sleeping for 1 millisecond sleeps for about 2 milliseconds. sleeping for 5 seconds sleeps for 5 seconds. </p> <p> Micro and milliseconds are doubling, but seconds are not doubling. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 14 Sep 2014 13:57:48 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/8136#comment:10 https://svn.boost.org/trac10/ticket/8136#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Niall, do you think this could be related to you improvement with GetTickCount64 or the PR related to WinRT? </p> Ticket viboes Sun, 14 Sep 2014 20:23:31 GMT summary changed https://svn.boost.org/trac10/ticket/8136#comment:11 https://svn.boost.org/trac10/ticket/8136#comment:11 <ul> <li><strong>summary</strong> <span class="trac-field-old">boost::this_thread::sleep_for() sleeps longer than it should in Windows</span> → <span class="trac-field-new">[windows] boost::this_thread::sleep_for() sleeps longer than it should in Windows</span> </li> </ul> Ticket viboes Tue, 23 Sep 2014 00:18:12 GMT milestone changed https://svn.boost.org/trac10/ticket/8136#comment:12 https://svn.boost.org/trac10/ticket/8136#comment:12 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.54.0</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> Ticket viboes Tue, 23 Sep 2014 00:20:45 GMT owner, status changed https://svn.boost.org/trac10/ticket/8136#comment:13 https://svn.boost.org/trac10/ticket/8136#comment:13 <ul> <li><strong>owner</strong> changed from <span class="trac-author">viboes</span> to <span class="trac-author">Niall Douglas</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket viboes Fri, 26 Sep 2014 06:06:23 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8136#comment:14 https://svn.boost.org/trac10/ticket/8136#comment:14 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket viboes Fri, 26 Sep 2014 06:09:52 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/8136#comment:15 https://svn.boost.org/trac10/ticket/8136#comment:15 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket Niall Douglas Sat, 04 Oct 2014 19:35:35 GMT <link>https://svn.boost.org/trac10/ticket/8136#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8136#comment:16</guid> <description> <p> I ran this test on Win8.1 x86 using VS2013 release x86 build on Boost trunk (1.57): </p> <p> 1015707 </p> <p> I ran it a few more times, all were minor variations around 1015xxx. </p> <p> I'd say this bug is stale. </p> <p> Niall </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 11 Oct 2014 05:27:02 GMT</pubDate> <title>status changed; resolution set; milestone deleted https://svn.boost.org/trac10/ticket/8136#comment:17 https://svn.boost.org/trac10/ticket/8136#comment:17 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> <li><strong>milestone</strong> <span class="trac-field-deleted">Boost 1.57.0</span> </li> </ul> Ticket