[Issue 16230] New: core.atomic.atomicLoad removes shared from aggregate types too eagerly
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sun Jul  3 05:32:47 PDT 2016
    
    
  
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 at puremagic.com
          Reporter: ag0aep6g at 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. */
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list