Click to See Complete Forum and Search --> : Simple question about CWinThread's ResumeThread()


Dan|]
September 22nd, 2005, 07:00 AM
Hello,

Just a(naive) question - or two - about resuming a thread, created suspended.
1. Let's say that we have a class:

"
//MyThreads header
...
class MyThread :: public CWinThread {

...
BOOL InitInstance();
Procedure();
...
HANDLE m_hEventKill;/* in the contructor is initialized m_hEventKill = CreateEvent(NULL, TRUE, FALSE, NULL);*/
};

//MyThread implementation

BOOL MyThread::InitInstance()
{
...//init stuff
while (WaitForSingleObject(m_hEventKill, 0) == WAIT_TIMEOUT)
Procedure();

return FALSE;
};
"

The question is as follows: if the m_hEventKill HANDLE signals the thread to exit instance at a certain phase in the Procedure(), when it is resumed it shall actually start from the very phase it exited ?

2. If yes, is there possible to serialize the thread to be thus resumed ?

Thank you,

MikeAThon
September 22nd, 2005, 08:25 PM
First and foremost, it doesn't seem that you need a UI thread. You are doing all your work in InitInstance(), which therefore will not return until after Procedure() function has completed. That means that the thread's Run() function can never begin the message loop. Moreover, you return FALSE from InitInstance which means that the thread will exit immediately anyway. Taken together, it's clear that a plain worker thread will suffice, and that there's no need for a UI thread.

As for your main question:The question is as follows: if the m_hEventKill HANDLE signals the thread to exit instance at a certain phase in the Procedure(), when it is resumed it shall actually start from the very phase it exited ?

No, the processing that was interrupted from inside of Procedure() will not resume from the point of interruption if you signal the m_hEventKill event. Signalling the event causes the thread to terminate completely, and there's nothing left to "resume".

Mike

Marc G
September 23rd, 2005, 02:03 AM
[ moved thread ]

Dan|]
September 23rd, 2005, 07:21 AM
What I needed is to offer the user a possibility to stop the Procedure() if it takes too much time. And ideally make it possible to be continued or resumed at another time. But it seems that this has to do more with data structures and algorithms, I mean the implementation of what Procedure() actually does.

MikeAThon
September 23rd, 2005, 07:37 PM
']What I needed is to offer the user a possibility to stop the Procedure() if it takes too much time. And ideally make it possible to be continued or resumed at another time. But it seems that this has to do more with data structures and algorithms, I mean the implementation of what Procedure() actually does.
That's probably correct. It should be possible to do what you want, but it depends heavily on proper implementation of your Procedure() function.

Mike