2017-02-25 47 views
-2

所以我有這個FUNC ..併發地圖迭代和地圖寫入錯誤Golang 1.8

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 
} 

是FUNC 3號線(用於DMN,解析:=範圍店)是給我的錯誤併發地圖迭代並在Golang 1.8中映射寫入錯誤。任何想法?

回答

2

看起來像Concurrent Map Misuse。可能是你從不同的gorotines調用的函數。嘗試將函數體封裝在mutex.Lock()/ Unlock()中,以便您的映射對於併發使用是安全的。

0

有一個在Golang 1.8添加了增強的併發訪問檢查,這是在運行時/ hashmap.go的源代碼:736,

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