Oh, my GoD! Goroutines on D
Jin
nin-jin at ya.ru
Fri Jan 3 21:41:37 UTC 2025
On Friday, 3 January 2025 at 00:17:27 UTC, Guillaume Piolat wrote:
> On Thursday, 2 January 2025 at 19:59:26 UTC, Jin wrote:
>> If someone can tell me what could be wrong here, I would be
>> very grateful.
>
> https://github.com/nin-jin/go.d/blob/master/source/jin/go/queue.d#L67
>
> A concurrent `put` and `popFront` will do nothing to avoid
> races in `Queue`.
> Individual access to _offset is atomic but its point of use in
> both put and popFront is not.
>
> Both functions look like this:
>
> 1. Atomic-read-offset
> 2. Anything can happen
> 3. Atomic-write-offset
>
> If one function has completed 1) then other has completed 1+2+3
> then you get a race.
> Chaining two atomic things doesn't make the whole atomic,
> rather classic mistake with mutual exclusion.
I didn't really understand what you were talking about. After
checking pending/available, we are guaranteed to have the
opportunity to take the next step on consumer/provider side.
Therefore, we are doing our job and then increasing our offset.
More information about the Digitalmars-d
mailing list