]> Cypherpunks repositories - gostls13.git/commit
runtime: use atomic.Cas to change timerRemoved to timerWaiting
authorIan Lance Taylor <iant@golang.org>
Fri, 1 Nov 2019 05:46:27 +0000 (22:46 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 1 Nov 2019 22:07:56 +0000 (22:07 +0000)
commitdc39be8b858ab0ef49ff7d87f3d4c5cb93403f1a
treebb65980f52020509d60a2b41a0b428007166c30d
parent130f3c061765f4f22da23ebf2fd4f7d0b137d826
runtime: use atomic.Cas to change timerRemoved to timerWaiting

If multiple goroutines call time.(*Timer).Reset then the timer will go
from timerWaiting to timerDeleted to timerModifying to timerModifiedLater.
The timer can be on a different P, meaning that simultaneously cleantimers
could change it from timerDeleted to timerRemoving to timerRemoved.
If Reset sees timerRemoved, it was doing an atomic.Store of timerWaiting,
meaning that it did not necessarily see the other values set in the timer,
so the timer could appear to be in an inconsistent state. Use atomic.Cas
to avoid that possibility.

Updates #6239
Updates #27707
Fixes #35272

Change-Id: I1d59a13dc4f2ff4af110fc6e032c8c9d59cfc270
Reviewed-on: https://go-review.googlesource.com/c/go/+/204717
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/time.go