In some circumstance, i would copy some content to different piece of the slice. Like this
a := make([]int, 10)
for i := 0; i < 10; i++ {
b := []int{i}
go func(i int) {
copy(a[i:i+1], b)
}(i)
}
time.Sleep(time.Second)
fmt.Println(a)
It leads DATA RACE
. But it always behave right in product environment.
So my question is:
- Any data race cloud be undefined behavior?
- Can i always get right result in such a practice?