Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: fix map iterator concurrent map check
We should check whether there is a concurrent writer at the start of every mapiternext, not just in mapaccessK (which is only called during certain map growth situations). Tests turned off by default because they are inherently flaky. Fixes #16278 Change-Id: I8b72cab1b8c59d1923bec6fa3eabc932e4e91542 Reviewed-on: https://go-review.googlesource.com/24749 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
- Loading branch information
Showing
3 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2016 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import "runtime" | ||
|
||
func init() { | ||
register("concurrentMapWrites", concurrentMapWrites) | ||
register("concurrentMapReadWrite", concurrentMapReadWrite) | ||
register("concurrentMapIterateWrite", concurrentMapIterateWrite) | ||
} | ||
|
||
func concurrentMapWrites() { | ||
m := map[int]int{} | ||
c := make(chan struct{}) | ||
go func() { | ||
for i := 0; i < 10000; i++ { | ||
m[5] = 0 | ||
runtime.Gosched() | ||
} | ||
c <- struct{}{} | ||
}() | ||
go func() { | ||
for i := 0; i < 10000; i++ { | ||
m[6] = 0 | ||
runtime.Gosched() | ||
} | ||
c <- struct{}{} | ||
}() | ||
<-c | ||
<-c | ||
} | ||
|
||
func concurrentMapReadWrite() { | ||
m := map[int]int{} | ||
c := make(chan struct{}) | ||
go func() { | ||
for i := 0; i < 10000; i++ { | ||
m[5] = 0 | ||
runtime.Gosched() | ||
} | ||
c <- struct{}{} | ||
}() | ||
go func() { | ||
for i := 0; i < 10000; i++ { | ||
_ = m[6] | ||
runtime.Gosched() | ||
} | ||
c <- struct{}{} | ||
}() | ||
<-c | ||
<-c | ||
} | ||
|
||
func concurrentMapIterateWrite() { | ||
m := map[int]int{} | ||
c := make(chan struct{}) | ||
go func() { | ||
for i := 0; i < 10000; i++ { | ||
m[5] = 0 | ||
runtime.Gosched() | ||
} | ||
c <- struct{}{} | ||
}() | ||
go func() { | ||
for i := 0; i < 10000; i++ { | ||
for range m { | ||
} | ||
runtime.Gosched() | ||
} | ||
c <- struct{}{} | ||
}() | ||
<-c | ||
<-c | ||
} |