// JP opened flex table

Click to See Complete Forum and Search --> : Thread suspended or not ?


jvr2
March 25th, 2004, 07:57 AM
Hello,

I'm writing a multithreaded application, using the CWinThread-class.

I create a thread :

m_pThread = AfxBeginThread(ThreadProc, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
m_pThread->m_bAutoDelete = false;

The thread is started/pauzed by using :

m_pThread->ResumeThread();
m_pThread->SuspendThread();

I want to know if it's possible to check if the thread is currently 'running' or 'suspended'.

If the thread is suspended at that time, I don't want it to be started !
So, using the return value of ResumeThread is not an option.


J.

VictorN
March 25th, 2004, 08:23 AM
Try to check the return value ("The thread’s previous suspend count ") of SuspendThread/ResumeThread:
if return value is zero - current thread was not suspended;
if return value is above zero - that thread does not execute;
if return value is 0xFFFFFFFF - either of these functions failed.

Andreas Masur
March 25th, 2004, 09:11 AM
[Moved thread]

jvr2
March 26th, 2004, 02:38 AM
I knew that, but I guess I cannot use the return value of the SuspendThread/ResumeThread functions !

Suppose a thread is currently suspended. If I use ResumeThread () to check its return value, the thread will be resumed, and I don't want that. I only wanted to know its actual state.

On the other hand, suppose a thread is currently active. If I use SuspendThread () to check its return value, the thread will be suspended instead of proceeding the processing ...

//JP added flex table