Lazy initialization with singleton pattern

后端 未结 2 1664
無奈伤痛
無奈伤痛 2021-01-04 06:32

Would the following code facilitate lazy initialization?
Or would the singletonInstance be created as soon as somebody includes the header

2条回答
  •  清酒与你
    2021-01-04 07:04

    This is known as the Meyers singleton and they are lazy instantiated.

    There are some considerations:

    • the singletons will be destroyed at the end of the program in the reverse order in which they are created, so there can be dependency issues.
    • C++03 doesn't guarantee against race conditions in multithreaded environments.

提交回复
热议问题