www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17048] New: Synchronized class methods give warnings for RMW


          Issue ID: 17048
           Summary: Synchronized class methods give warnings for RMW
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kirsybuu gmail.com

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

$ cat sync.d
import std.stdio;
synchronized class Test {
    private int x = 0;
    int get() { return ++x; }
unittest {
    shared Test o = new Test();
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.

Dec 30 2016