Deprecation: Read-modify-write operations are not allowed for shared variables

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 12 03:21:00 PDT 2014


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.


More information about the Digitalmars-d-learn mailing list