Singleton & Multi-threading

后端 未结 6 597
有刺的猬
有刺的猬 2021-01-05 17:36

I have the following class

class Singleton
{
  private:

    static Singleton *p_inst;
    Singleton();

  public:

    static Singleton * instance()
             


        
6条回答
  •  抹茶落季
    2021-01-05 18:14

    You will have to use a mutex and lock the pointer before assigning or reading it, making this a slow (and imo just plain terrible) design pattern.

提交回复
热议问题