Problem mit Signalhandler



  • Hallo zusammen,

    habe folgendes Problem:

    mein Main:

    static bool m_RunApplication = false
    
    int main(int32 argc, char* argv[])
    {
      if(argc != 2)
      {
        return 0;
      }
      filename = argv[1];
      initProg();
    
      //install the handles for update and for exit with ctrl+c
      installHandles();
    
      m_RunApplication = true;
      while(m_RunApplication)
      {
        runProg();
      }
      deInitProg();
      return 0;
    }
    

    installHandles()

    void installHandles()
    {
    	//signal for the cyclic update
    	struct sigaction sa;
    	struct itimerval timer;
    
    	//signal for close the application
    	struct sigaction exit;
    
    	//install timer_handler as the signal for SIGVTALRM   
    	memset(&sa, 0 , sizeof(sa) );
    	sa.sa_handler = &timer_handler;
    	sigaction(SIGVTALRM , &sa , NULL);
    
    	//Configure the timer to expire after 100msec...
    	timer.it_value.tv_sec = 0;
    	timer.it_value.tv_usec = 100000;
    
    	//...and every 100ms after that.   
    	timer.it_interval.tv_sec = 0;
    	timer.it_interval.tv_usec = 100000;
    
    	//Start the virtual timer
    	setitimer(ITIMER_VIRTUAL, &timer, NULL);
    
    	//install signal ctrl+c
    	exit.sa_handler = &exit_handler;
    	sigaction(SIGINT , &exit , NULL);
    }
    

    und zu letzt exit_handler

    void exit_handler(int signum)
    {
    	m_RunApplication = false;
    }
    

    Das ganze funktioniert einwandfrei. Aber sobald ich vor dem Aufruf des installHandles() (in main bevor Zeile 13) ein

    std::cout << " test" << std::endl;
    

    einfüge wird nach dem drücken von ctrl+c ein Core Dump erstellt.

    Hat jemand eine Ahnung wieso das passiert?


Anmelden zum Antworten