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

          Issue ID: 17048
           Summary: Synchronized class methods give warnings for RMW
                    operations
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

Synchronized class methods are implicitly (and undocumentedly?) typed as
shared, thus they can only be called from shared instances of the class and DMD
treats the bodies of their methods as shared even though they are used with
mutual exclusion. A synchronized method should not be treated the same as other
shared methods due to this guarantee, such as allowing the following safe code.

This depreciation warning is printed by DMD v2.072.1 and v2.071.0 but not
v2.070.0.

$ cat sync.d
import std.stdio;
synchronized class Test {
    private int x = 0;
    int get() { return ++x; }
}
pragma(msg,typeof(Test.get));
unittest {
    shared Test o = new Test();
    writeln(o.get());
}
kirsybuu@kirsybuntu:~/Desktop/2017 Spring/Dlang Jan Meetup$ rdmd -unittest
-main sync.d
shared int()
sync.d(4): Deprecation: read-modify-write operations are not allowed for shared
variables. Use core.atomic.atomicOp!"+="(this.x, 1) instead.
1

--

Reply via email to