C++ Logo


Advanced search

Re: [std-proposals] unique_lock<atomic_flag>

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 22 Feb 2023 22:20:43 -0800
On Tuesday, 21 February 2023 23:17:11 PST Frederick Virchanza Gotham via Std-
Proposals wrote:
> If you double-lock a mutex, the behaviour is undefined. A recursive
> mutex is of no use either because we don't want the same thread to be
> able to re-enter.

Then don't double-lock it. You can use try_lock().

Now, std::mutex are usually heavy-weight because they retain compatibility
with the platform's mutex type (pthread_mutex_t). Without that need and
without the ability to interoperate with condition_variable, they can be made
much simpler, the same size and complexity as a binary_semaphore.

See previous posts by Marko Mäkelä on the subject. His code:

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-02-23 06:20:45