#11368 closed Bugs (fixed)
boost thread's usage of CreateWaitableTimer wakes PC from sleep (doh)
Reported by: | denger | Owned by: | viboes |
---|---|---|---|
Milestone: | Boost 1.60.0 | Component: | thread |
Version: | Boost 1.58.0 | Severity: | Regression |
Keywords: | Cc: | raad@… |
Description
Hi,
after upgrading to boost 1.58 from 1.57 a lot of users complained that my app was prematurely aborting the PC's sleep state. The culprit can easily detected and it was indeed my process: "powercfg /lastwake"
It shows that the process had set a "wake timer". The changes in boost/libs/thread/src/win32/thread.cpp seem to be the cause.
Please remove usage of "CreateWaitableTimer" in function "interruptible_wait()" or at least provide some means (preprocessor variable, whatever) to allow compilation of boost::thread without "CreateWaitableTimer".
Thanks
Change History (20)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
CreateWaitableTimer is used by two functions in boost/libs/thread/src/win32/thread.cpp:
bool interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time) bool non_interruptible_wait(detail::win32::handle handle_to_wait_for,detail::timeout target_time)
follow-up: 6 comment:3 by , 7 years ago
The problem isn't the use of waitable timers per se, but the use of SetWaitableTimerEx
, which always wakes the system from sleep if possible. Boost.Thread should revert to using plain SetWaitableTimer
, ensuring that false
is passed for the bResume
parameter so that the timer doesn't wake the system.
comment:4 by , 7 years ago
but the use of SetWaitableTimerEx
You're right! I have reverted thread.cpp from version 1.58 to 1.57 and my users have confirmed that the unexpected wake up problem is solved! So this is indeed a boost regression after 1.57.
follow-up: 8 comment:6 by , 7 years ago
Replying to anonymous:
The problem isn't the use of waitable timers per se, but the use of
SetWaitableTimerEx
, which always wakes the system from sleep if possible. Boost.Thread should revert to using plainSetWaitableTimer
, ensuring thatfalse
is passed for thebResume
parameter so that the timer doesn't wake the system.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/8047b845-2a1b-4220-a4b7-b10234bce924/unable-to-resume-in-windows-7-through-set-waitable-timer?forum=vcgeneral claimed that resumption of power from SetWaitableTimerEx didn't work. I therefore made the untested assumption that the WAKE_CONTEXT I passed didn't wake the machine.
I'll test that over here and see what I can figure out. The Microsoft documentation on WAKE_CONTEXT approaches nil unfortunately.
Niall
comment:7 by , 7 years ago
Cc: | added |
---|
comment:8 by , 7 years ago
Replying to ned14:
I'll test that over here and see what I can figure out. The Microsoft documentation on WAKE_CONTEXT approaches nil unfortunately.
I'll be honest: until the AFIO review and then CppCon is over, I won't have the time to investigate this. Anyone else willing to take it on is welcome.
Niall
comment:9 by , 7 years ago
We have the same issue with 1.58. Any updates on a fix for this?
Thanks!
Markus
follow-up: 11 comment:10 by , 7 years ago
Hi, I believe that we will need to wait until Niall has some time to look at this. I'm unable to test on Windows and don't the Windows interface well.
comment:11 by , 7 years ago
Replying to viboes:
Hi, I believe that we will need to wait until Niall has some time to look at this. I'm unable to test on Windows and don't the Windows interface well.
I gave it a quick test on my Win8.1 machine here and found no wakes from sleep. I'd suggest it's something in the system settings maybe. I didn't have much time though, it was only a very quick test.
I'd suggest reverting the patch I committed. I am no longer employed by the client who wanted that patch, so I have no objections for it returning to the previous code as that is less hassle for everybody.
Niall
comment:13 by , 7 years ago
Replying to viboes:
Niall please, be free to do it.
I'm on vacation from Boost library development until January. Had enough of Boost for a while.
But if someone else raises a pull request on github reverting the commit, I will check it and approve it.
Niall
comment:14 by , 7 years ago
This pull request fixes the issue, passing null as REASON_CONTEXT is not document but works according to tests we made.
comment:16 by , 7 years ago
Milestone: | To Be Determined → Boost 1.60.0 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:17 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:20 by , 6 years ago
The fix is in 1.60, as you can tell from the tag of the commit on github.
Test system: Windows 7 x64