C++, is set_terminate local to every thread?

前端 未结 4 894
无人共我
无人共我 2021-02-07 14:11

Should set_terminate/get_terminate set a different terminate exception processor for several threads in C++ 2011 or C++ 2003?

E.g. if I have pr

4条回答
  •  半阙折子戏
    2021-02-07 14:35

    In the Standard it says under

    18.8.3.2 set_terminate [set.terminate]

    terminate_handler set_terminate(terminate_handler f) noexcept;

    1 Effects: Establishes the function designated by f as the current handler function for terminating exception processing.

    [[noreturn]] void terminate() noexcept;

    2 Effects: Calls the current terminate_handler function. [ Note: A default terminate_handler is always considered a callable handler in this context. —end note ]

    You can see that terminate() calls the current terminate handler, which in the set_handler section it quite clearly says it is used for terminating a process. This gets called when all other exception handling has failed, irrespective from which thread is running.

    There is only one terminate handler, and it always gets called from wherever the program is terminating.

提交回复
热议问题