C++ Logo


Advanced search

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

From: Marko Mäkelä <marko.makela_at_[hidden]>
Date: Mon, 30 Aug 2021 17:25:35 +0300
Mon, Aug 30, 2021 at 04:48:33PM +0300, Ville Voutilainen via Std-Proposals wrote:
>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.

I realize that my analogy to the dimensions of physical objects was a
little flawed, because it implied that we would aim to standardize a
type with an exact size. Indeed, it would only be of a "small" size.

Best regards,


Received on 2021-08-30 09:25:43