💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
> # 并发迭代有写(插入/删除)报错: 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) } ~~~