Fixing core.atomic
rm
rymrg at memail.com
Wed Jun 2 15:09:54 UTC 2021
On 02/06/2021 17:59, Ola Fosheim Grøstad wrote:
> On Wednesday, 2 June 2021 at 14:08:32 UTC, rm wrote:
>> It's useful if you want to implement known concurrency algorithms with
>> SC semantics. Such as lamports lock (which requires SC).
>
> Have you ever used Lamport's Bakery, though?
Not Lamport's Bakery. But I did implement some primitives. betterC does
limit the options to work with phobos.
For the other cases, I do start with explicit syntax. As I start with
strong accesses and try to relax them as I progress. But that's mostly
because I want try use the weaker memory semantics.
> Atomic inc/dec are obviously useful, but usually you want to know what
> the value was before/after the operation, so fetch_add/compare_exchange
> are easier to deal with IMO.
What's wrong with this?
```D
Atomic!int x = 5;
int a = x+; // a = 5
```
https://github.com/rymrg/drm/blob/9db88fb468e2b8babdf9bde488d28d733aea638f/atomic.d#L95
inc/dec are implemented in terms of fetch_add.
More information about the Digitalmars-d
mailing list