C++ Logo


Advanced search

Re: [std-proposals] Idea for a "null" mutex

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 2 Jan 2023 09:46:21 +0000
On Monday, January 2, 2023, Simon Scatton via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> So that for instance if I want a thread safe Output, I use this:
> Output<std::mutex> A;
> And if I want a non-thread safe Output I use this:
> Output<NullMutex> B;

What if you were to pass around an 'std::optional<std::mutex>'?

Then the likes of 'lock_guard' and 'unique_lock' could be given a new
overloaded constructor:

template<class MutexType>
class lock_guard {
    lock_guard(std::optional<MutexType> &arg)
        if ( arg.has_value() ) p_mtx = &arg.value();

Received on 2023-01-02 09:46:24