Skip to content

MutexProtected to internally use std::shared_ptr / std::weak_ptr? #3295

@Lestropie

Description

@Lestropie

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions