1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:14:46 -07:00

runtime: convert local var cunlock at doTestParallelReaders to atomic type

For #53821

Change-Id: I17440ea30827976a8d3755851a2496f26aea13b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/427137
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
cuiweixie 2022-09-02 10:37:16 +08:00 committed by Daniel Martí
parent 7d83d320c0
commit 02700e55a5

View File

@ -17,10 +17,10 @@ import (
"testing"
)
func parallelReader(m *RWMutex, clocked chan bool, cunlock *uint32, cdone chan bool) {
func parallelReader(m *RWMutex, clocked chan bool, cunlock *atomic.Bool, cdone chan bool) {
m.RLock()
clocked <- true
for atomic.LoadUint32(cunlock) == 0 {
for !cunlock.Load() {
}
m.RUnlock()
cdone <- true
@ -30,7 +30,7 @@ func doTestParallelReaders(numReaders int) {
GOMAXPROCS(numReaders + 1)
var m RWMutex
clocked := make(chan bool, numReaders)
var cunlock uint32
var cunlock atomic.Bool
cdone := make(chan bool)
for i := 0; i < numReaders; i++ {
go parallelReader(&m, clocked, &cunlock, cdone)
@ -39,7 +39,7 @@ func doTestParallelReaders(numReaders int) {
for i := 0; i < numReaders; i++ {
<-clocked
}
atomic.StoreUint32(&cunlock, 1)
cunlock.Store(true)
// Wait for the goroutines to finish.
for i := 0; i < numReaders; i++ {
<-cdone