Junior — Senior
Unsynchronized access to map from multiple goroutines
livecode
Task condition
Determine what output will appear in the console, considering that multiple goroutines are writing values to a regular map simultaneously without any synchronization. Pay attention to the possible consequences of data races.
func main() {
data := make(map[int]bool)
for i := 0; i < 10; i++ {
go func() {
data[i] = true
}()
}
time.Sleep(time.Second * 5)
for k, v := range data {
fmt.Println(k, v)
}
}