aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/map_faststr.go
diff options
context:
space:
mode:
authorZachary Amsden <zach@thundertoken.com>2018-07-31 11:24:37 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2018-08-22 21:38:27 +0000
commit37ea182660e31f4e21b2bc34d2438455269e5f78 (patch)
tree000bd6854492f34d1634e7f0c90bf09d57a6d9a2 /src/runtime/map_faststr.go
parent773e89464560833711c2554420d1a1550e0e8ff3 (diff)
downloadgo-37ea182660e31f4e21b2bc34d2438455269e5f78.tar.gz
go-37ea182660e31f4e21b2bc34d2438455269e5f78.zip
runtime: catch concurrent stacks more often
If two goroutines are racing on a map, one of them will exit cleanly, clearing the hashWriting bit, and the other will likely notice and panic. If we use XOR instead of OR to set the bit in the first place, even numbers of racers will hopefully all see the bit cleared and panic simultaneously, giving the full set of available stacks. If a third racer sneaks in, we are no worse than the current code, and the generated code should be no more expensive. In practice, this catches most racing goroutines even in very tight races. See the demonstration program posted on https://github.com/golang/go/issues/26703 for an example. Fixes #26703 Change-Id: Idad17841a3127c24bd0a659b754734f70e307434 Reviewed-on: https://go-review.googlesource.com/126936 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/map_faststr.go')
-rw-r--r--src/runtime/map_faststr.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/map_faststr.go b/src/runtime/map_faststr.go
index 415bbff143..bee62dfb03 100644
--- a/src/runtime/map_faststr.go
+++ b/src/runtime/map_faststr.go
@@ -202,7 +202,7 @@ func mapassign_faststr(t *maptype, h *hmap, s string) unsafe.Pointer {
hash := t.key.alg.hash(noescape(unsafe.Pointer(&s)), uintptr(h.hash0))
// Set hashWriting after calling alg.hash for consistency with mapassign.
- h.flags |= hashWriting
+ h.flags ^= hashWriting
if h.buckets == nil {
h.buckets = newobject(t.bucket) // newarray(t.bucket, 1)
@@ -294,7 +294,7 @@ func mapdelete_faststr(t *maptype, h *hmap, ky string) {
hash := t.key.alg.hash(noescape(unsafe.Pointer(&ky)), uintptr(h.hash0))
// Set hashWriting after calling alg.hash for consistency with mapdelete
- h.flags |= hashWriting
+ h.flags ^= hashWriting
bucket := hash & bucketMask(h.B)
if h.growing() {