C++ Logo

std-discussion

Advanced search

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

From: liusiwei <liusiwei_at_[hidden]>
Date: Thu, 3 Jun 2021 10:11:30 +0800
Thanks for your confirmation!

Yeah, the method name is confusing. My bad...

Regards

> 2021年6月2日 下午2:33,Jason McKesson via Std-Discussion <std-discussion_at_[hidden]> 写道:
>
> 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.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2021-06-02 21:11:37