digitalmars.D.learn - is increment on shared ulong atomic operation?
- Charles Hixson via Digitalmars-d-learn (11/11) Feb 07 2016 If I define a shared ulong variable, is increment an atomic operation?
- rsw0x (2/14) Feb 07 2016 https://dlang.org/phobos/core_atomic.html#.atomicOp
- rsw0x (5/26) Feb 07 2016 Just noticed that there's no example.
- Minas Mina (2/29) Feb 07 2016 Wow, that syntax sucks a lot.
- rsw0x (3/17) Feb 07 2016 how so?
- Andrea Fontana (3/9) Feb 08 2016 a.atomicOp!"+="(1);
- Charles Hixson via Digitalmars-d-learn (7/31) Feb 07 2016 Thanks, that's what I needed to know.
If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared struct are synced, then the operation on a shared variable should be synced, but "+=" is clearly stated not to be synchronized, so I'm uncertain.
Feb 07 2016
On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote:If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared struct are synced, then the operation on a shared variable should be synced, but "+=" is clearly stated not to be synchronized, so I'm uncertain.https://dlang.org/phobos/core_atomic.html#.atomicOp
Feb 07 2016
On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote:On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote:Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1);If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared struct are synced, then the operation on a shared variable should be synced, but "+=" is clearly stated not to be synchronized, so I'm uncertain.https://dlang.org/phobos/core_atomic.html#.atomicOp
Feb 07 2016
On Sunday, 7 February 2016 at 19:43:23 UTC, rsw0x wrote:On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote:Wow, that syntax sucks a lot.On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote:Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1);If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared struct are synced, then the operation on a shared variable should be synced, but "+=" is clearly stated not to be synchronized, so I'm uncertain.https://dlang.org/phobos/core_atomic.html#.atomicOp
Feb 07 2016
On Sunday, 7 February 2016 at 20:25:44 UTC, Minas Mina wrote:On Sunday, 7 February 2016 at 19:43:23 UTC, rsw0x wrote:how so? It's meant to be very explicitOn Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote:Wow, that syntax sucks a lot.On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote:Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1);[...]https://dlang.org/phobos/core_atomic.html#.atomicOp
Feb 07 2016
On Sunday, 7 February 2016 at 20:25:44 UTC, Minas Mina wrote:a.atomicOp!"+="(1); sounds better. You can alias it too.Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1);Wow, that syntax sucks a lot.
Feb 08 2016
Thanks, that's what I needed to know. I'm still going to do it as a class, but now only the inc routine needs to be handled specially. (The class is so that other places where the value is used don't even need to know that it's special. And so that instances are easy to share between threads.) On 02/07/2016 11:43 AM, rsw0x via Digitalmars-d-learn wrote:On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote:On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote:Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1);If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared struct are synced, then the operation on a shared variable should be synced, but "+=" is clearly stated not to be synchronized, so I'm uncertain.https://dlang.org/phobos/core_atomic.html#.atomicOp
Feb 07 2016