[Issue 17048] New: Synchronized class methods give warnings for RMW operations
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Dec 30 19:28:09 PST 2016
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: nobody at puremagic.com
Reporter: kirsybuu at 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
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 at 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
--
More information about the Digitalmars-d-bugs
mailing list