Why does this C++ static singleton never stop?

前端 未结 6 608
旧时难觅i
旧时难觅i 2020-12-28 08:48

i have implemented a singleton (static version) in C++. I know all the controversy about this pattern and potential thread-safety issues, but i am curious why this exact imp

6条回答
  •  醉话见心
    2020-12-28 09:14

    See [basic.start.term] in the Standard:

    If there is a use of a standard library object or function not permitted within signal handlers (18.10) that does not happen before (1.10) completion of destruction of objects with static storage duration and execution of std::atexit registered functions (18.5), the program has undefined behavior. [Note: If there is a use of an object with static storage duration that does not happen before the object’s destruction, the program has undefined behavior. Terminating every thread before a call to std::exit or the exit from main is sufficient, but not necessary, to satisfy these requirements. These requirements permit thread managers as static-storage-duration objects. —end note ]

提交回复
热议问题