🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
> # 并发迭代有写(插入/删除)报错: concurrent map iteration and map write ~~~ package main import ( "time" ) func main() { m := make(map[int]int) for i := 0; i < 1000; i++ { m[i] = i } for i := 0; i < 100; i++ { go func() { for j := 0; j < 1000; j++ { go func() { for k, _ := range m { _ = k } }() } }() } // 启动 100 个 goroutine 执行写操作 for i := 0; i < 1000; i++ { delete(m, i) } time.Sleep(time.Second * 10) } ~~~