LDC optimized builds causing unexpected behaviour when sharing variable between threads
kinke
noone at nowhere.com
Wed Jun 1 16:46:51 UTC 2022
On Wednesday, 1 June 2022 at 13:35:45 UTC, Keivan Shah wrote:
> probably will use
> [core.atomic.atomicFence](https://dlang.org/phobos/core_atomic.html#.atomicFence) to ensure the memoryOrdering.
`core.atomic.atomic{Load,Store}` handle this:
```
void main()
{
import std.stdio : writeln;
import core.thread;
import core.atomic;
writeln("Starting...");
shared bool done = false;
new Thread({ atomicStore(done, true); }).start();
while (!atomicLoad(done))
{
} // Wait for done
writeln("Done!");
}
``
More information about the digitalmars-d-ldc
mailing list