"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
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)
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