I created three worker threads to work for two simultaneous runs at each time and one control (main) thread. The main thread is waiting while two (sub) thread are processing. Then,once the main get any finish signal from those two, it check if it needs to create another run or to stop. The user specify the limit count to stop. I don't want to stop the loop in the main thread unless both two threads finished their runs. Therefore, I made the main thread 'while' loop to go on til both finish.
I don't know it is right to do for running 2 threads at the same time. (actually 3 including main thread).
The problem is it works well sometimes and it doesn't.
For example of problem, the user set 4 runs. Run1 and Run2 start together. Run1 finish first but Run2 stil running. Run1 needs to do 'third' process by creating new thread from main thread. It doesn't do that process and stops. Run2 keeps on running till the current process finishes and go on with third process.
Finally, run2 finish running til the end (forth run) and the loop in main thread never gets out. Meaning that the whole process "hanging" there. After I check the 'while' loop is going on and on. Why is it that way?
I think the logical variables are not stable or something is very wrong. Sometimes, it goes very smoothly.
Hard to say, but CloseHandle is not needed with CWinThread - it is closed automatically if you use autodelete.
And your use of events is superfluous. You can wait directly on the thread handle instead, but then you have to turn off autodelete.
Hard to say, but CloseHandle is not needed with CWinThread - it is closed automatically if you use autodelete.
And your use of events is superfluous. You can wait directly on the thread handle instead, but then you have to turn off autodelete.
Thanks for your reply. zerver. Yes, I used many events and I think may be they are causing me this problem. I will try as you told me and post my outcomes and question if any.
nankyu
Last edited by nankyu; November 12th, 2008 at 07:04 PM.
Zerver, your post helped me to solve the problem. Thanks alot.
Since I used many events and I checked its object's status to control the loop. Now I used few events and no problem occurs.
I think after 'SetEvent()' call for a event, I can see that its object equals to 'WAIT_OBJECT_0'. But as it was looping and called for 'SetEvent()' certain times, its object changed and not equal to 'WAIT_OBJECT_0' anymore (I think that is a problem).
Bookmarks