Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#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 anonymous, 7 years ago

Test system: Windows 7 x64

comment:2 by anonymous, 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)

comment:3 by anonymous, 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 anonymous, 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.

comment:5 by viboes, 7 years ago

Owner: changed from Anthony Williams to Niall Douglas

Niall, please could you take a look.

in reply to:  3 ; comment:6 by Niall Douglas, 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 plain SetWaitableTimer, ensuring that false is passed for the bResume 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 raad@…, 7 years ago

Cc: raad@… added

in reply to:  6 comment:8 by Niall Douglas, 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 anonymous, 7 years ago

We have the same issue with 1.58. Any updates on a fix for this?

Thanks!

Markus

comment:10 by viboes, 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.

in reply to:  10 comment:11 by Niall Douglas, 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:12 by viboes, 7 years ago

Niall please, be free to do it.

in reply to:  12 comment:13 by Niall Douglas, 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 Mikael Olenfalk, 7 years ago

This pull request fixes the issue, passing null as REASON_CONTEXT is not document but works according to tests we made.

https://github.com/boostorg/thread/pull/67

comment:15 by viboes, 7 years ago

Niall, what do you think of the patch? What others think?

comment:16 by viboes, 7 years ago

Milestone: To Be DeterminedBoost 1.60.0
Owner: changed from Niall Douglas to viboes
Status: newassigned

comment:17 by viboes, 7 years ago

Resolution: fixed
Status: assignedclosed

comment:18 by anonymous, 7 years ago

what version is the issue fixed in ?

comment:19 by anonymous, 6 years ago

Who can tell which version has the fix? is it 1.61.0?

comment:20 by raad@…, 6 years ago

The fix is in 1.60, as you can tell from the tag of the commit on github.

Note: See TracTickets for help on using tickets.