Golang 1.8中的并发地图迭代和地图写入错误

So I have this func..

func Set(firstSet map[string][]App, store map[string]*Parsed) map[string][string]struct{} {
    s := make(map[string]map[string]struct{})
    for dmn, parsed := range store {
        for cId, apps := range firstSet {
            if _, ok := s[dmn]; !ok {
                s[dmn] = make(map[string]struct{})
            }
            s[dmn][cId] = struct{}{}
        }
    }

    return s
}

Line 3 of that func (for dmn, parsed := range store) is giving me the error concurrent map iteration and map write error in Golang 1.8. any idea?

It looks like Concurrent Map Misuse . Probably your function invoked from different gorotines. Try to enclose function body in mutex.Lock()/Unlock() so that your map is safe for concurrent use.

There is a enhanced concurrent access check added in the Golang 1.8, and this is the source code in runtime/hashmap.go:736,

if h.flags&hashWriting != 0 {
    throw("concurrent map iteration and map write")
}