You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"sync"
)
func main() {
var m *sync.WaitGroup
m = &sync.WaitGroup{}
for i := 0; i < 100; i++ {
go func(m *sync.WaitGroup) {
m.Add(1)
}(m)
}
m.Wait()
}
and got a data race warning:
WARNING: DATA RACE
Write at 0x00c04200e03c by main goroutine:
internal/race.Write()
D:/Go/src/internal/race/race.go:41 +0x3f
sync.(*WaitGroup).Wait()
D:/Go/src/sync/waitgroup.go:129 +0xfb
main.main()
C:/Users/Lifang/go/src/ago.go:15 +0xbb
Previous read at 0x00c04200e03c by goroutine 5:
internal/race.Read()
D:/Go/src/internal/race/race.go:37 +0x3f
sync.(*WaitGroup).Add()
D:/Go/src/sync/waitgroup.go:71 +0x176
main.main.func1()
C:/Users/Lifang/go/src/ago.go:12 +0x48
I am confused.. Is it the Add() function should not call in other goroutine?
The text was updated successfully, but these errors were encountered:
I run the below code with race detector
and got a data race warning:
I am confused.. Is it the Add() function should not call in other goroutine?
The text was updated successfully, but these errors were encountered: