What does the following runtime error mean: “terminate called without an active exception\n Aborted”

后端 未结 5 1379
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 07:15

The bug disturbed me about two days: when running the code I have a runtime error of \"terminate called without an active exception\\n Aborted\",why?

I try to locate the

5条回答
  •  别跟我提以往
    2021-02-15 07:48

    Like Gearoid Murphy said the error happens when the thread object is destructed before the thread function itself has been fully executed. I detected this error using tinythread library (http://tinythreadpp.bitsnbites.eu/):

    Before:

    #include "tinythread.h"
    ...
    void fork_thread(void (*function_pointer)(void * arg), void * arg_pointer) {
        tthread::thread t(function_pointer, arg_pointer);
        // t is destructed here, causing the "terminate called ..." error
    }
    

    After:

    #include "tinythread.h"
    ...
    void fork_thread(void (*function_pointer)(void * arg), void * arg_pointer) {
        tthread::thread * t = new tthread::thread(function_pointer, arg_pointer);
        // now the new thread object is not destructed here, preventing
        // the "terminate called ..." error. Remember that because thread
        // object must now be destructed explicitly (i.e. manually) with delete
        // call you should store the pointer t to a vector of thread pointers
        // for example.
    }
    

提交回复
热议问题