Append not thread-safe?
问题 I noticed that if I tried appending to a slice using goroutines inside a for loop, there would be instances where I would get missing/blank data: destSlice := make([]myClass, 0) var wg sync.WaitGroup for _, myObject := range sourceSlice { wg.Add(1) go func(closureMyObject myClass) { defer wg.Done() var tmpObj myClass tmpObj.AttributeName = closureMyObject.AttributeName destSlice = append(destSlice, tmpObj) }(myObject) } wg.Wait() Sometimes, when I print all AttributeName s from destSlice ,