Not if you use the return value. The return value itself is a
temporary, whose lifetime extends beyond the end of the function; it
will be destructed at the end of the full expression which calls
A::clone_a. So if you write something like:
shared_ptr<int> newA = object->clone_a();
, the formal semantics will be for the temporary returned by
object->clone_a() to be copied into newA, in the context of the
caller (and so unprotected by the mutex). In this particular case, you
may get away with it because of RVO, but that won't necessarily be the
case, and there are other cases where RVO can't intervene.
If all you're worried about is the copy of the pointer, I'm pretty sure
that if you set the right compiler options (-D
somthing), boost::shared_ptr will behave atomically. In
this case, you don't need the mutex at all.