-
Notifications
You must be signed in to change notification settings - Fork 197
MutexProtected to internally use std::shared_ptr / std::weak_ptr? #3295
Description
Relates to discussion in #3277, and MutexProtected class introduced in #2778 / #2755.
It was proposed in the former that std::shared_ptr<> be used for data to be shared across multiple worker threads requiring update upon destruction, each locally storing a std::weak_ptr<> to force access of those data to be very explicit.
However the latter involves ongoing use of reference member variables within worker thread classes in order to acquire the lock when required. Reference member variables is precisely what the use of <memory> was intended to obviate.
I'm wondering if the best structure here is a class that integrates functionalities of both of these. The class would offer a member class for worker threads to copy-construct from, which would act pretty much as a std::weak_ptr<>. Obtaining access to the class would involve not just promotion to the equivalent of a std::shared_ptr<>, but also acquisition of a mutex lock.