Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"machine sleep" + WaitForSingleObject + finite timeout

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?

like image 580
pweyzen Avatar asked May 09 '12 06:05

pweyzen


2 Answers

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.

like image 55
Urmas Rahu Avatar answered Oct 16 '22 12:10

Urmas Rahu


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.

like image 27
Andrew Avatar answered Oct 16 '22 12:10

Andrew