August 12, 2014 Deprecation: Read-modify-write operations are not allowed for shared variables | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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? |
August 12, 2014 Re: Deprecation: Read-modify-write operations are not allowed for shared variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | 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.
|
Copyright © 1999-2021 by the D Language Foundation