C++ Logo

std-proposals

Advanced search

Re: [std-proposals] unique_lock<atomic_flag>

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Wed, 22 Feb 2023 11:47:43 +0300
On 2/22/23 03:02, Frederick Virchanza Gotham via Std-Proposals wrote:
> I think 'lock_guard' and 'unique_lock' should be usable with atomic_flag.
>
> The constructor would do:
>
> while ( f.test_and_set() ) f.wait(true);
>
> And the destructor would do:
>
> f.clear();
>
> Furthermore, 'try_lock' would simply be:
>
> return false == f.test_and_set();
>
> Also defer_lock, adopt_lock and try_to_lock would be easily
> implementable as constructor arguments.

atomic_flag is not a Lockable type, why would a lock work with it?

If you want a mutex based on atomic_flag then you should write one and
use that with lock types.

Received on 2023-02-22 08:47:57