C++, is set_terminate local to every thread?

前端 未结 4 910
无人共我
无人共我 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

    17.6.4.7p4 says:

    Calling the set_* and get_* functions shall not incur a data race. A call to any of the set_* functions shall synchronize with subsequent calls to the same set_* function and to the corresponding get_* function.

    This strongly implies that the set_* and get_* functions are operating on the same global state even when called from different threads. All the paragraphs under 18.8.3 discuss "the current handler function", with no other mention of threading; this indicates that the handler function is a property of the program as a whole; similarly, 17.6.4.7 has:

    2 - A C++ program may install different handler functions during execution [...]
    3 - A C++ program can get a pointer to the current handler function by calling the following functions [...]

    These paragraphs discuss the current handler function in the context of a program, indicating that it is program-scope and not thread-local.

提交回复
热议问题