Home > Software engineering >  How to stop another thread to Sleep, and immediately execute that code?
How to stop another thread to Sleep, and immediately execute that code?

Time:11-20

My software with Sleep function in one thread, such as Sleep2 seconds, but when the computer shutdown, I want this thread to immediately stop the Sleep, and perform the back of the code, how to operate?
Because when shutdown, threads may have begun to Sleep, and the computer shutdown process will not wait for you after this thread, so lead to the back of the code is not performed, do you have a solution?

CodePudding user response:

Threads do not use the Sleep function

CodePudding user response:

Unwrapped Sleep for 2 seconds to execute, judge mark
 DWORD dwOut=GetTickCount () + 2000. 
While ((! BExitFlag) & amp; & The GetTickCount () & lt; DwOut)
{
Sleep (1);
}


CodePudding user response:

Don't Sleep, for 1 second with a timeout WaitForSingleObject
So you can set the signal at any time in the main thread wait to finish it,

CodePudding user response:

reference Jiang Sheng reply: 3/f
don't have to Sleep, with a timeout for 1 second WaitForSingleObject
So you can set the signal at any time in the main thread to wait end,
  • Related