Menu

Thread crash

Help
2001-06-21
2001-08-06
  • Daniel Etzold

    Daniel Etzold - 2001-06-21

    Hi,
    how can I prevent my parent from crashing when one of its threads crashes?
    The following example causes the thread to crash but its father, too.

    #include <iostream>
    #include "cc++/thread.h"

    class A : public Thread
    {
      public:
        A() { };
      protected:
        virtual void Run()
          {
            cout << "hello" << endl;
            int *p = 0;
            *p = 10;   // force crash
          }
    };

    int main()
    {
      A *a = new A();
      a->Start();
      while(1) sleep(1);
    }

    thanks

     
    • Václav Haisman

      Václav Haisman - 2001-06-24

      I think you have to use try-catch in Run() so that you can handle the exception.

       
      • Václav Haisman

        Václav Haisman - 2001-06-24

        Strange, I tested it with try-catch in Run() and it still crashes.

         
    • David Sugar

      David Sugar - 2001-08-06

      C++ Exception handling cannot cross thread boundries.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.