core.stdc.stdatomic

Stefan Koch uplink.coder at googlemail.com
Fri Nov 17 09:36:04 UTC 2023


On Friday, 17 November 2023 at 04:12:32 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> On 17/11/2023 11:50 AM, claptrap wrote:
>> LF algorithms rely on a sequence of operations being done in a 
>> specific order, and that order being coherent across 
>> cores/threads.
>
> Yes but there is a condition on this:
>
> 1. Each operation must be atomic, or:
> 2. Operate on an atomically synchronized memory
>
> But most importantly:
> 3. Must be predictable
>
> When you don't inline you get additional steps added that may 
> not hold this condition. Where it can be not atomic and not 
> operating on non-atomically synchronized memory.
>
> This is why it matters that it doesn't inline. It adds 
> variability between the steps so that it isn't doing what you 
> think the algorithm is doing. It introduces unpredictability.

when you rely on more than one operation being atomic you are 
already on the loosing team.
Just because two operations are right next to each other in the 
machine code, it does not mean the will be executed right after 
each other.
Another thread or processor might invalidate the condition you 
established with the first instruction that the other is relying 
on.
Therefore your algorithm is only correct if you are not relying 
on predictable execution order.


More information about the Digitalmars-d mailing list