C++ Logo

std-discussion

Advanced search

Re: Does the standard guarantee that shared_from_this is thread safe?

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 2 Jun 2021 02:33:10 -0400
I'm more concerned about the fact that you called that method "clone".
The name strongly suggests that you expect to be getting an object
wholly distinct from the object you "cloned". You won't; you're just
getting a shared-pointer to the same object.

As far as thread safety is concerned, the behavior of
`shared_from_this` is required to be identical to the behavior of
constructing a `shared_ptr<T>` from a `weak_ptr<T>`. This does not
provoke a data race.

Received on 2021-06-02 01:33:26