www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16230] New: core.atomic.atomicLoad removes shared from

https://issues.dlang.org/show_bug.cgi?id=16230

          Issue ID: 16230
           Summary: core.atomic.atomicLoad removes shared from aggregate
                    types too eagerly
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

import core.atomic;

struct S { int* p; }
class C { int i; }

shared int i = 0;
shared int* p = &i;
shared int[] a = [0];
shared S s = shared S(&i);
shared C c = new C;

void main()
{
    auto j = atomicLoad(i);
    pragma(msg, typeof(j)); /* "int" - Ok, it's a copy. */

    auto q = atomicLoad(p);
    pragma(msg, typeof(q)); /* "shared(int)*" - Good. */

    auto b = atomicLoad(a);
    pragma(msg, typeof(b)); /* "shared(int)[]" - Good. */

    auto t = atomicLoad(s);
    pragma(msg, typeof(t)); /* "S" - Bad. */

    auto d = atomicLoad(c);
    pragma(msg, typeof(d)); /* "C" - Bad. */

    /* t and d refer to shared data, but their types are completely
    un-shared. The point of shared has been defeated.

    For example, I can now accidentally use ++ on the ints: */

    ++*t.p; /* No deprecation. Bad. */
    ++d.i; /* Ditto. */

    /* With q and b I get a deprecation message, because they're
    properly typed: */ 

    ++*q; /* "Deprecation: read-modify-write operations are not allowed
        for shared variables. Use core.atomic.atomicOp!"+="(*q, 1)
        instead." Good. */
    ++b[0]; /* Ditto. */
}

--
Jul 03 2016