Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/race/timer_test.go

Documentation: runtime/race

     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  // +build race
     7  
     8  package race_test
     9  
    10  import (
    11  	"sync"
    12  	"testing"
    13  	"time"
    14  )
    15  
    16  func TestTimers(t *testing.T) {
    17  	const goroutines = 8
    18  	var wg sync.WaitGroup
    19  	wg.Add(goroutines)
    20  	var mu sync.Mutex
    21  	for i := 0; i < goroutines; i++ {
    22  		go func() {
    23  			defer wg.Done()
    24  			ticker := time.NewTicker(1)
    25  			defer ticker.Stop()
    26  			for c := 0; c < 1000; c++ {
    27  				<-ticker.C
    28  				mu.Lock()
    29  				mu.Unlock()
    30  			}
    31  		}()
    32  	}
    33  	wg.Wait()
    34  }
    35  

View as plain text