Why do "const inout" and "const inout shared" exist?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 2 06:48:34 PDT 2017


On 07/02/2017 09:39 AM, Timon Gehr wrote:
> In general, depending on the hardware memory model and the language 
> memory model, data transfer from one thread to another requires 
> cooperation from both parties. We don't want the thread that has the 
> unshared data to need to participate in such a cooperation.

Yes, there must be a handshake. Oh, I see your point. Let me illustrate:

void fun(const shared int* p1)
{
    auto a = atomicLoad(p1);
    ...
}

void gun()
{
     int* p = new int;
     shared const int* p1 = p; // assume this passes
     spawn(&fun, p);
     *p = 42; // should be a shared write, it's not
}

Is this what you're referring to?

So it seems like the hierarchy in http://erdani.com/conversions.svg is 
minimal?


Andrei


More information about the Digitalmars-d mailing list