7

Strange question here -- but:

If I use WaitForSingleObject on a mutex with a 20 minute timeout. Then, the machine enters sleep mode (or hibernate) while waiting.... Upon wake 12 hours later -- will my call to WaitForSingleObject time-out? or will the timer suspend with the machine sleep?

pweyzen
  • 151
  • 4

3 Answers3

3

According to https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx, WaitForSingleObject does take time spent in low-power states into account, but only starting from Windows 8. So on Windows 7 it should behave as described above, but on Windows 8 and later the call will time out only when the system has been actively running for the requested amount of time.

Urmas Rahu
  • 313
  • 1
  • 8
  • It seems you have problems with english. The MSDN says exactly the OPPOSITE: Windows 8 and 10: " The dwMilliseconds value does not include time spent in low-power states. For example, the timeout does not keep counting down while the computer is asleep." – Elmue Nov 20 '17 at 16:34
1

Just tested on Windows 7 with 5 minutes timeout and 10 minutes sleep. I was waiting for endless thread.

Surprise - WaitForSingleObject was timed out after my machine waked up.

Andrew
  • 3,696
  • 3
  • 40
  • 71
1

Excerpt from MSDN:

Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008 and Windows Server 2008 R2: The dwMilliseconds value does include time spent in low-power states. For example, the timeout does keep counting down while the computer is asleep.

Windows 8, Windows Server 2012, Windows 8.1, Windows Server 2012 R2, Windows 10 and Windows Server 2016: The dwMilliseconds value does not include time spent in low-power states. For example, the timeout does not keep counting down while the computer is asleep.

JasonE
  • 894
  • 6
  • 8