blob: dd59005564273abc0749742c99bd3bdb8151d495 [file] [log] [blame]
Patrice Arruda748609c2020-06-25 12:12:21 -07001// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Dan Willemsencc753b72021-08-31 13:25:42 -07005//go:build race
Patrice Arruda748609c2020-06-25 12:12:21 -07006
7package race_test
8
9import (
10 "sync"
11 "testing"
12 "time"
13)
14
15func TestTimers(t *testing.T) {
16 const goroutines = 8
17 var wg sync.WaitGroup
18 wg.Add(goroutines)
19 var mu sync.Mutex
20 for i := 0; i < goroutines; i++ {
21 go func() {
22 defer wg.Done()
23 ticker := time.NewTicker(1)
24 defer ticker.Stop()
25 for c := 0; c < 1000; c++ {
26 <-ticker.C
27 mu.Lock()
28 mu.Unlock()
29 }
30 }()
31 }
32 wg.Wait()
33}