Hi all. I'm using QT 3.3.1 on Windows and have an application with a QThread object. An exit command could come from 2 different places: the user closing the window or an external application that I'm hooking to exiting.

The child thread is responsible for communicating with the external app and posting when the exit has occurred. I have 2 booleans to indicate where the exit command has come from. If the exit command came from the GUI, then guiCommandedExit is set to true. If the exit came from the external app, then externalCommandedExit is set to true. Before checking/setting either of those flags, I do a myMutex.lock( ). After the check/set, I do myMutex.unlock( ).

The problem that I'm running into is that when the exit event occurs (through the GUI), I'm getting a large number of "First-chance exception in [my_app].exe" along with a stack overflow notice. This is the first time I've done anything with threads since Operating Systems 1 in college, so forgive me if I'm missing something obvious. Any help that can be provided is appreciated. Thanks in advance.

Qt Code:
  1. class MyThread
  2. {
  3.  
  4. public:
  5. void run( );
  6.  
  7. };
  8.  
  9. MyThread::run( )
  10. {
  11.  
  12. while ((!/*externally commanded exit*/) && (!guiCommandedExit))
  13. {
  14.  
  15. /* communicate with the external app */
  16.  
  17. }/* end while no exit */
  18.  
  19. myMutex.lock( );
  20.  
  21. if (!guiCommandedExit)
  22. {
  23.  
  24. /* post to close the GUI */
  25. externalCommandedExit = true;
  26.  
  27. }
  28.  
  29. myMutex.unlock( );
  30.  
  31. }/* end ::run */
  32.  
  33. void
  34. MainGui::closeEvent( QCloseEvent* event )
  35. {
  36.  
  37. myMutex.lock( );
  38.  
  39. if (!externalCommandedExit)
  40. {
  41.  
  42. guiCommandedExit = true;
  43.  
  44. myMutex.unlock( );
  45.  
  46. myThread->wait( );
  47.  
  48. }
  49.  
  50. QApplication::exit( 0 );
  51.  
  52. event->accept( );
  53.  
  54. }/* end ::closeEvent */
To copy to clipboard, switch view to plain text mode