MCPcopy
hub / github.com/hoanhan101/ultimate-go / main

Function main

go/concurrency/data_race_4.go:39–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39func main() {
40 // wg is used to manage concurrency.
41 var wg sync.WaitGroup
42 wg.Add(1)
43
44 // Create a writer Goroutine that performs 10 different writes.
45 go func() {
46 for i := 0; i < 10; i++ {
47 time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
48 writer(i)
49 }
50 wg.Done()
51 }()
52
53 // Create eight reader Goroutines that runs forever.
54 for i := 0; i < 8; i++ {
55 go func(i int) {
56 for {
57 reader(i)
58 }
59 }(i)
60 }
61
62 // Wait for the write Goroutine to finish.
63 wg.Wait()
64 fmt.Println("Program Complete")
65}
66
67// writer adds a new string to the slice in random intervals.
68func writer(i int) {

Callers

nothing calls this directly

Calls 4

writerFunction · 0.85
AddMethod · 0.80
readerFunction · 0.70
WaitMethod · 0.65

Tested by

no test coverage detected