Opened 10 years ago
Closed 8 years ago
#8136 closed Bugs (worksforme)
[windows] boost::this_thread::sleep_for() sleeps longer than it should in Windows
Reported by: | Owned by: | Niall Douglas | |
---|---|---|---|
Milestone: | Component: | thread | |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Calling the this_thread::sleep_for() results in a sleep almost twice as long as desired.
code:
#include <iostream> #include <boost/thread.hpp> 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 << (boost::chrono::duration_cast<boost::chrono::microseconds>(end - start)).count() << std::endl; return 0; }
When built in MS Windows 7 x64, the program outputs 2000114
The same code in linux x64 outputs 1000298
Change History (17)
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 10 years ago
Milestone: | To Be Determined → Boost 1.54.0 |
---|
Please, could you check if the following update works for you?
Committed in trunk revision [83282].
follow-up: 5 comment:4 by , 10 years ago
I cannot link without BOOST_USE_WINDOWS_H defined.
With BOOST_USE_WINDOWS_H defined, it works ok.
Shouldn't be the test in thread/win32/thread_primitives.hpp:21
#if _WIN32_WINNT >= 0x0600
instead of
#if WINNT >= 0x0600
MS Visual Studio (IDE) doesn't know WINNT, but is happy with _WIN32_WINNT
comment:5 by , 10 years ago
Replying to Ondrej Siler <ondrej.siler@…>:
I cannot link without BOOST_USE_WINDOWS_H defined.
With BOOST_USE_WINDOWS_H defined, it works ok.
Shouldn't be the test in thread/win32/thread_primitives.hpp:21
#if _WIN32_WINNT >= 0x0600instead of
#if WINNT >= 0x0600MS Visual Studio (IDE) doesn't know WINNT, but is happy with _WIN32_WINNT
I suspect that you are talking of #8070, isn't it?
comment:6 by , 10 years ago
Yes, you are right. According to MSDN: "To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later."
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Committed revision [83525].
comment:9 by , 8 years ago
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.
Micro and milliseconds are doubling, but seconds are not doubling.
comment:10 by , 8 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Niall, do you think this could be related to you improvement with GetTickCount64 or the PR related to WinRT?
comment:11 by , 8 years ago
Summary: | boost::this_thread::sleep_for() sleeps longer than it should in Windows → [windows] boost::this_thread::sleep_for() sleeps longer than it should in Windows |
---|
comment:12 by , 8 years ago
Milestone: | Boost 1.54.0 → Boost 1.57.0 |
---|
comment:13 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:14 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:15 by , 8 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:16 by , 8 years ago
I ran this test on Win8.1 x86 using VS2013 release x86 build on Boost trunk (1.57):
1015707
I ran it a few more times, all were minor variations around 1015xxx.
I'd say this bug is stale.
Niall
comment:17 by , 8 years ago
Milestone: | Boost 1.57.0 |
---|---|
Resolution: | → worksforme |
Status: | reopened → closed |
I have no access to a windows machine now. Could you do the test for 5 seconds? and 100ms?