Date: Wed, 2 Jun 2021 08:34:55 +0800
Hi all,
The standard seems not mention the thread-safety info on shared_from_this. However, cpppreference state :
> Effectively executes std::shared_ptr(weak_this), where weak_this is the private mutable std::weak_ptr member of enable_shared_from_this.
Can I take it as a guarantee that it's safe to call shared_from_this in multiple threads? Since if I understand correctly, constructing a shared_ptr with a shared_ptr or weak_ptr object, is thread safe.
Take the following code as an example:
class A : public std::enable_shared_from_this<A> { public: std::shared_ptr<A> clone() { return shared_from_this(); } };
In this case, can I call A::clone() in multiple threads?
Regards
The standard seems not mention the thread-safety info on shared_from_this. However, cpppreference state :
> Effectively executes std::shared_ptr(weak_this), where weak_this is the private mutable std::weak_ptr member of enable_shared_from_this.
Can I take it as a guarantee that it's safe to call shared_from_this in multiple threads? Since if I understand correctly, constructing a shared_ptr with a shared_ptr or weak_ptr object, is thread safe.
Take the following code as an example:
class A : public std::enable_shared_from_this<A> { public: std::shared_ptr<A> clone() { return shared_from_this(); } };
In this case, can I call A::clone() in multiple threads?
Regards
Received on 2021-06-01 19:35:11