title: Is Singleton object returned through shared_ptr thread-safe?
body: <p>I was reading the answers to the question. <a href="https://stackoverflow.com/questions/1008019/c-singleton-design-pattern">C++ Singleton design pattern</a></p>
  
  <p>One of the <a href="https://stackoverflow.com/a/40337728/3282470">answer</a> suggested to use shared_ptr to guarantee the lifetime when multiple  static objects access the singleton object. I noticed that shared_ptr here is constructed using new and is returned by value.</p>
  
  <p>Is using new for shared_ptr construction atomic/thread_safe?</p>
  
  <p>My second confusion is regarding RVO. I tried creating two singleton objects in my implementation. </p>
  
  <p>The shared_ptr shows three _Uses and one _Weak. I expected _Uses count to be two. Optimization is full on Visual Studio 15.5.6.
  Is RVO not functioning here?</p>
  
  <pre><code>class Singleton
  {
  public:
      Singleton(Singleton const&amp;) = delete;
      Singleton&amp; operator=(Singleton const&amp;) = delete;
  
  static std::shared_ptr&lt;Singleton&gt; instance()
  {
      static std::shared_ptr&lt;Singleton&gt; s{new Singleton};
      return s;
  }
  
      ~Singleton() {}
  private:
      Singleton() {}
  };
  
  int main()
  {
       std::shared_ptr&lt;Singleton&gt; obj1 = Singleton::instance();
       std::shared_ptr&lt;Singleton&gt; obj2 = Singleton::instance();
       return 0;
  }
  </code></pre>