C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Copy-construct, move-construct, and PR-construct

From: Thiago Macieira <thiago_at_[hidden]>
Date: Wed, 13 Sep 2023 19:22:54 -0700
On Wednesday, 13 September 2023 19:10:07 PDT Thiago Macieira wrote:
> anyway, the point isn't that we're *returning* a type. What we're doing is
> create it in-place of where it shall exist once the function has returned.

Here's a challenge then:

Return not one but two immovable types (say, std::mutex and
std::condition_variable), without forcing the caller to use a specific type.
That is, initialise those two members in my class:

struct SharedMemory
{
    uint64_t magic
    std::mutex mutex;
    // pthread_mutex_t on Linux is only 40 bytes, so we can use this space
    int use_count;
    alignas(64) std::condition_variable cond;
};

And yes, std::mutex and std::condition_variable can be used in shared memory
on Linux and possibly other Unix OSes, if you can control the pthread_attr
used by the pthread_mutex_t inside, which is exactly what this particular
function would achieve.
-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-09-14 02:22:56