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: Ondrej Siler <ondrej.siler@…> 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 viboes, 10 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

I have no access to a windows machine now. Could you do the test for 5 seconds? and 100ms?

comment:2 by Ondrej Siler <ondrej.siler@…>, 10 years ago

Same behaviour - for 5 seconds sleeps 10 secs, for 100ms sleeps 200ms.

comment:3 by viboes, 10 years ago

Milestone: To Be DeterminedBoost 1.54.0

Please, could you check if the following update works for you?

Committed in trunk revision [83282].

comment:4 by Ondrej Siler <ondrej.siler@…>, 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

in reply to:  4 comment:5 by viboes, 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 >= 0x0600

instead of

#if WINNT >= 0x0600

MS 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 Ondrej Siler <ondrej.siler@…>, 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:7 by viboes, 10 years ago

Committed revision [83294][83318].

comment:8 by viboes, 10 years ago

Resolution: fixed
Status: assignedclosed

Committed revision [83525].

comment:9 by anonymous, 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 viboes, 8 years ago

Resolution: fixed
Status: closedreopened

Niall, do you think this could be related to you improvement with GetTickCount64 or the PR related to WinRT?

comment:11 by viboes, 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 viboes, 8 years ago

Milestone: Boost 1.54.0Boost 1.57.0

comment:13 by viboes, 8 years ago

Owner: changed from viboes to Niall Douglas
Status: reopenednew

comment:14 by viboes, 8 years ago

Resolution: fixed
Status: newclosed

comment:15 by viboes, 8 years ago

Resolution: fixed
Status: closedreopened

comment:16 by Niall Douglas, 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 viboes, 8 years ago

Milestone: Boost 1.57.0
Resolution: worksforme
Status: reopenedclosed
Note: See TracTickets for help on using tickets.