C++ Logo


Advanced search

Re: Slim mutexes and locks based on C++20 std::atomic::wait

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 30 Aug 2021 16:48:33 +0300
On Sat, 28 Aug 2021 at 19:26, Jason McKesson via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> > I think that the ability to "embed" a lock inside a concurrent data
> > structure is a very compelling reason to have std::atomic based
> > alternatives to std::mutex and std::shared_mutex. For example, if the
> > cache line size is 64 bytes, one 4-byte atomic_mutex can protect 15
> > other 4-byte elements located in the same cache line. As a byproduct of
> > acquiring the mutex, you will already have loaded the data to the L1
> > cache. (Not necessarily all data, but the "head" of the protected data
> > structure.)
> C++ as a standard assiduously *avoids* defining the size of anything.
> A byte is defined as being of size 1, but even that doesn't require
> that it be precisely 8 bits.

Sure, but the reason to standardize this type is that it's designed to
be portably very small,
whereas std::mutex isn't.

Received on 2021-08-30 08:48:45