Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetThreadExecutionState with ES_CONTINUOUS - what happens if app crashes before resetting flags

Tags:

c++

winapi

I am going to use SetThreadExecutionState WinAPI function to keep system running during a certain job.

SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);

According to MSDN, application must clear the flags set after the job is done if ES_CONTINUOUS is used.

If my application crashed during the job, I would not be able to clear the flags that were set earlier. My question is, will the system clear the flags set by the app when app terminates or will the system remain awake?

like image 657
Lahiru Chandima Avatar asked Oct 18 '25 04:10

Lahiru Chandima


1 Answers

Yes, the system will clear (or, more accurately, discard) the flags when the thread that set them no longer exists.

It doesn't matter whether the thread exited cleanly or was terminated.

NB: I can only confirm from my own experience that the flags will be ignored once the process has exited, but the name of the function strongly implies that the flags are set per-thread rather than per-process.

like image 90
Harry Johnston Avatar answered Oct 19 '25 16:10

Harry Johnston