I'm reading http://gcc.gnu.org/onlinedocs/libstdc++/manual/shared_ptr.html and some thread safety issues are still not clear for me:
- Standard guarantees that reference counting is handled thread safe and it's platform independent, right?
- Similar issue - standard guarantees that only one thread (holding last reference) will call delete on shared object, right?
- shared_ptr does not guarantee any thread safety for object stored in it?
EDIT:
Pseudo code:
// Thread I
shared_ptr<A> a (new A (1));
// Thread II
shared_ptr<A> b (a);
// Thread III
shared_ptr<A> c (a);
// Thread IV
shared_ptr<A> d (a);
d.reset (new A (10));
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?
make_shared
instead ofnew
– qdii