Lite
asked on
All or nothing
How to make a group of statements act as one instruction? All of them are executed without being interrupted by other thread or none is executed.
Here is the trouble I meet:
Several threads are used in my project and I want to suspend certain threads in some conditions. I use following statements:
::GetExitCodeThread( pThread->hThread, &dwExitCode );
if( dwExitCode == STILL_ACTIVE ){
pThread->SuspendThread();
}
// pThread is the point to the thread
I have to make these statements act as one statement so that the thread will not quit and pThread is valid when "pThread->SuspendThread()" is executed.
Thanks in advance!
Here is the trouble I meet:
Several threads are used in my project and I want to suspend certain threads in some conditions. I use following statements:
::GetExitCodeThread( pThread->hThread, &dwExitCode );
if( dwExitCode == STILL_ACTIVE ){
pThread->SuspendThread();
}
// pThread is the point to the thread
I have to make these statements act as one statement so that the thread will not quit and pThread is valid when "pThread->SuspendThread()"
Thanks in advance!
<<...the thread will not quit and pThread is
valid when "pThread->SuspendThread()" is executed>>
Looks like that pThread becomes invalid when the thread terminated. If so then your code is wrong in principle.
If the thread already exited then you cannot execute even ::GetExitCodeThread( pThread->hThread, &dwExitCode );
valid when "pThread->SuspendThread()"
Looks like that pThread becomes invalid when the thread terminated. If so then your code is wrong in principle.
If the thread already exited then you cannot execute even ::GetExitCodeThread( pThread->hThread, &dwExitCode );
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DanRollins,
the original question does not say that pThread points to CWinThread. The questioner believes that pThread becomes invalid once the thread exited.
I meant to say that if this is true, then it makes no sense to call GetExitCodeThread() at all.
the original question does not say that pThread points to CWinThread. The questioner believes that pThread becomes invalid once the thread exited.
I meant to say that if this is true, then it makes no sense to call GetExitCodeThread() at all.
ASKER
Thanks, everyone. I'v found an alternative way to bypass this complicated problem. I think the question can be resovled using event and critical section. But I don't want to spend my time on it. :)
did you try ctritical sections or mutex (if your threads in different process)?