Change-Id: I021fbc9786a3e3f858770fe3e109a0de487390d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/426089
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: xie cui <
523516579@qq.com>
Reviewed-by: Damien Neil <dneil@google.com>
}
// goroutines counts the number of goroutines ever created; for testing.
-var goroutines int32
+var goroutines atomic.Int32
// propagateCancel arranges for child to be canceled when parent is.
func propagateCancel(parent Context, child canceler) {
}
p.mu.Unlock()
} else {
- atomic.AddInt32(&goroutines, +1)
+ goroutines.Add(1)
go func() {
select {
case <-parent.Done():
"runtime"
"strings"
"sync"
- "sync/atomic"
"time"
)
}
func XTestCustomContextGoroutines(t testingT) {
- g := atomic.LoadInt32(&goroutines)
+ g := goroutines.Load()
checkNoGoroutine := func() {
t.Helper()
- now := atomic.LoadInt32(&goroutines)
+ now := goroutines.Load()
if now != g {
t.Fatalf("%d goroutines created", now-g)
}
}
checkCreatedGoroutine := func() {
t.Helper()
- now := atomic.LoadInt32(&goroutines)
+ now := goroutines.Load()
if now != g+1 {
t.Fatalf("%d goroutines created, want 1", now-g)
}