title: std::shared_ptr thread safety explained
body: <p>I'm reading <a href="https://web.archive.org/web/20140318233637/http://gcc.gnu.org/onlinedocs/libstdc++/manual/shared_ptr.html" rel="noreferrer">http://gcc.gnu.org/onlinedocs/libstdc++/manual/shared_ptr.html</a> and some thread safety issues are still not clear for me:</p>
  <ol>
  <li>Standard guarantees that reference counting is handled thread safe and it's platform independent, right?</li>
  <li>Similar issue - standard guarantees that only one thread (holding last reference) will call delete on shared object, right?</li>
  <li>shared_ptr does not guarantee any thread safety for object stored in it?</li>
  </ol>
  <p>EDIT:</p>
  <p>Pseudo code:</p>
  <pre><code>// Thread I
  shared_ptr&lt;A&gt; a (new A (1));
  
  // Thread II
  shared_ptr&lt;A&gt; b (a);
  
  // Thread III
  shared_ptr&lt;A&gt; c (a);
  
  // Thread IV
  shared_ptr&lt;A&gt; d (a);
  
  d.reset (new A (10));
  </code></pre>
  <p>Calling reset() in thread IV will delete previous instance of A class created in first thread and replace it with new instance? Moreover after calling reset() in IV thread other threads will see only newly created object?</p>