www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Deprecation: Read-modify-write operations are not allowed for shared

reply Timothee Cour via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
dmd 2.066(rc) generates warning: 'Deprecation: Read-modify-write operations
are not allowed for shared variables. Use core.atomic.atomicOp!"-="(a, 1)
instead.' for following code:

synchronized {
  ++a;
}

Is that correct given that it's inside synchronized?
Aug 12 2014
parent "anonymous" <anonymous example.com> writes:
On Tuesday, 12 August 2014 at 10:01:46 UTC, Timothee Cour via
Digitalmars-d-learn wrote:
 dmd 2.066(rc) generates warning: 'Deprecation: 
 Read-modify-write operations
 are not allowed for shared variables. Use 
 core.atomic.atomicOp!"-="(a, 1)
 instead.' for following code:

 synchronized {
   ++a;
 }

 Is that correct given that it's inside synchronized?
I think yes. Only this specific block is synchronized (only one thread can run it at a time). Other accesses of `a` elsewhere are not synchronized with this one. If you know that this `synchronized` block is enough to make it safe, you can cast shared away.
Aug 12 2014