Source file src/runtime/race/timer_test.go

     1  // 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  
     5  //go:build race
     6  
     7  package race_test
     8  
     9  import (
    10  	"sync"
    11  	"testing"
    12  	"time"
    13  )
    14  
    15  func 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  }
    34  

View as plain text