On Tue, Feb 9, 2021 at 11:18 AM xie cui <cuiwei...@gmail.com> wrote:
>
> https://github.com/golang/go/blob/master/src/runtime/proc.go#L5926
> how the cas in this line  avoid ABA problem?

The ABA problem occurs if some thread compares the value to A, and
then a different thread changes the value to B and then changes it
back to A, such that the initial thread gets confused about the state.
That can't happen here because the value in runqhead always increases,
and to make that work the value is always used modulo the length of
the run queue.  Since the value always increases no ABA problem is
possible, because the other thread will never set the field back to an
earlier value.  (It's technically possible for runqhead to be
incremented so many times that it wraps around to the original value,
but as runqhead is a 32-bit value that would require some 0x2000000
increments before the thread runs again, which is implausible.)

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVzVW9-aMOS0f-zSQhG6W6Ki5kb7%3D8aGXfJx0MkkSy7-A%40mail.gmail.com.

Reply via email to