Hi I have been trying to figure out this problem for a while now. I have a simple code that uses 1 thread. When I call the destructor, I set a variable to allow the thread to end naturally, i.e return with 0.
The following code works in the debug version but if I compile a release version, it sometimes hangs right after printing fallthrough. It does not do any of the switch cases. I have to use control C to kill the program. DEBUG is 1 and the logfile stream has not been closed yet.
Sorry forgot to add that I use MS Visual studio .net 2003
Any help would be highly appreciated
Thanks a bunch,
Amish
Code:waitError = WaitForSingleObject(readThread,10000); /* Wiat until thread is done */ std::cout << "fallthrough\n"; endThread = 0; /* Reset the ending of the read thread*/ readThread = NULL; switch(waitError) { /* Perform different actions depending on what caused wait to fallthrough*/ case WAIT_ABANDONED: logfile << "5) WaitForSingleObject() in class serialCom was abandoned\n"; logfile.flush(); #ifdef DEBUG std::cout << "Wait abandoned\n"; #endif break; case WAIT_OBJECT_0: logfile << "6) WaitForSingleObject() in class serialCom falled through with return 0\n"; logfile.flush(); #ifdef DEBUG std::cout << "Wait object 0\n"; #endif break; case WAIT_TIMEOUT: logfile << "7) WaitForSingleObject() in class serialCom timed out\n"; logfile.flush(); #ifdef DEBUG std::cout << "Wait timeout\n"; #endif break; case WAIT_FAILED: logfile << "8) WaitForSingleObject() in class serialCom failed\n"; logfile.flush(); #ifdef DEBUG std::cout << "Wait failed\n"; #endif break; default : logfile << "9) Unknown error reported from WaitForSingleObject() in class serialCom\n"; logfile.flush(); #ifdef DEBUG std::cout << "Unknown wait error\n"; #endif break; } }