Thread: release version issue

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    205

    release version issue

    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;
    		}
    	}
    Last edited by axr0284; 01-26-2006 at 12:54 PM. Reason: Sorry forgot to add that I use MS Visual studio .net 2003

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > It does not do any of the switch cases.
    Just guessing, but does logfile actually do anything in a release build?

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    Quote Originally Posted by Salem
    > It does not do any of the switch cases.
    Just guessing, but does logfile actually do anything in a release build?
    It should, logfile is a file output stream.
    Amish

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Maybe so, but is it implemented differently in release mode
    - like is it opened
    - is it opened, but mapped to the NUL device say
    - Are all the methods implemented as empty functions, so no actual code gets run?

    In short, do you
    logfile << "something";
    from anywhere else in the program, and does that actually appear?

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    This is weird. I tried the following:
    Code:
    logfile.open("serialCom.log",std::ios::out | std::ios::trunc); /*The log file where errors are written*/
    	if(logfile.is_open()) {
    		const char *logString = "Logfile has been opened and is ready to use\n";
    		logfile.write(logString,sizeof(*logString));
    		logfile << "Logfile has been opened and is ready\n";
    	logfile.flush();
    	logfile.close();
    std::cout << "logfile opened\n";
    	}
    
    	else {
    		std::cout << "logfile not opened\n";
    	}
    "logfile opened" gets printed to the command window properly so I assume the logfile was opened correctly but neither logfile.write nor logfile << seems to work. I am really confused about this situation.
    Amish

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > logfile.write(logString,sizeof(*logString));
    This would only write one character, even if it did work.

    Did you try this as a separate test program, on it's own with no chance that the result would be influenced by other (possibly incorrect) code?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Proxy/Stub issue
    By George2 in forum C++ Programming
    Replies: 0
    Last Post: 02-14-2008, 02:40 AM
  3. dumpbin with debug and release version
    By George2 in forum C Programming
    Replies: 5
    Last Post: 11-12-2007, 03:10 AM
  4. Dev C++ Version 5
    By Zoalord in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2003, 01:56 PM
  5. Version info?
    By Aidman in forum Tech Board
    Replies: 7
    Last Post: 07-03-2003, 10:44 AM