Looking for advice on pausing a thread

Hi all,

I am running a rather slow computation and I want to pause it. In the moment, I achieve that in a very sloppy manner:

First I split my GUI using _beginthread( GUIthread, 0, NULL );
With my GUIthread I pop up a window in the usual fashion and capture a button click from the user to modify a global variable bool Pause.

With the main thread I check at given stable points of the computation whether Pause is true. If it is true it is supposed to pause the program. If false it is supposed to resume. At the moment I do that in the sloppiest manner I can imagine (but it was the only one I came up with):
1
2
3
while(Pause)
{ ::Sleep(200);
}


What would you advise me to do?

Thank you for the advice!
Last edited on
If you create your thread with CreateThread() you can use the returned thread handle with SuspendThread() and ResumeThread().

CreateThread: http://msdn.microsoft.com/en-us/library/ms682453(VS.85).aspx
That means I must put my make my computational thread a not-main-thread. Will that slow down the thread's performance? My computations are supposed to be running for hours.

[Edit:] Did it exactly as you suggested! Thanks for the advice! Now I have to only figure out whether I lost performance...
Last edited on
Will that slow down the thread's performance?


I don't think so. It depends on what your "main" thread is doing.
Topic archived. No new replies allowed.