2020
12-23
12-23
快速解决Golang Map 并发读写安全的问题
一、错误案例packagemainimport("fmt""time")varTestMapmap[string]stringfuncinit(){TestMap=make(map[string]string,1)}funcmain(){fori:=0;i<1000;i++{goWrite("aaa")goRead("aaa")goWrite("bbb")goRead("bbb")}time.Sleep(5*time.Second)}funcRead(keystring){fmt.Println(TestMap[key])}funcWrite(keystring){TestMap[key]=key}上面代码执行大概率出现报错:fatalerror:c...
继续阅读 >