title: Facing concurrency issues with Go sync maps
body: <p>I am having problems with Go's <code>sync.Map</code>. Below are the details:</p>
  
  <p>I created a global sync map like:</p>
  
  <pre><code>var MySyncGlobalMap = sync.Map{}
  </code></pre>
  
  <p>and on an event I populate this map with the intended structure as 
  <code>map[int64]map[string]interface{}</code>. So basically I want to populate the <strong>sync map</strong> with key as <code>int64</code> and value as another <strong>sync map</strong> of structure <code>map[string]interface{}</code>. Below is how I populate the map:</p>
  
  <pre><code>//below is the innerSync map. recSet is returned from DB call in the format : []map[string]interface{}
  var innerSyncMap = sync.Map{}
  for _, record := range recSet {
  
      sKey := record["key"].(string)
      value := record["value"]
      innerSyncMap.Store(sKey, value)
  }
  MySyncGlobalMap.Store(jobID, innerSyncMap)
  </code></pre>
  
  <p>Now there will be multiple threads which will be accessing this map and do some operations. There will be constant updates to the inner sync map. Once the processing is done on the key of the inner sync map, that key will be deleted from that map. </p>
  
  <p>I will know that a job is complete once the inner sync map becomes empty. </p>
  
  <p>Now since there are multiple threads accessing this map I receiving a panic:</p>
  
  <blockquote>
    <p>Fatal error: concurrent read and write</p>
  </blockquote>
  
  <p>I am still wondering that even after using <strong>sync map</strong> I am facing this issue. </p>
  
  <p>Can any one point out what am I doing wrong?</p>