Oh, my GoD! Goroutines on D
Jin
nin-jin at ya.ru
Wed Jan 8 10:10:55 UTC 2025
On Monday, 6 January 2025 at 10:15:39 UTC, Jin wrote:
> I found a bug. I first checked if there was anything in the
> queue, and if not, I checked if the queue was finalized.
> Sometimes the queue would fill up between these two steps and I
> would lose data. I moved the finalization check to the
> beginning and now everything is stable.
I looked into the core.atomic code and was very disappointed. I
expected to see memory barriers (necessary for wait-free), but I
saw a CAS-spinlock there (and this is lock-free):
```d
asm pure nothrow @nogc @trusted
{
naked;
push RBX;
mov R8, RDX;
mov RAX, [RDX];
mov RDX, 8[RDX];
mov RBX, [RCX];
mov RCX, 8[RCX];
L1: lock; cmpxchg16b [R8];
jne L1;
pop RBX;
ret;
}
```
More information about the Digitalmars-d
mailing list