The reason for the error is that the map is thread unsafe and an error will be reported when there are concurrent reads and writes
solution: use the read-write lock sync.rwmutex:
golang read-write lock
rules
when the read lock exists, other read locks can exist together, but the write lock needs to wait
when the write lock exists, both the read lock and the write lock need to wait
the read lock can be concurrent, and the read lock and the write lock are mutually exclusive, Write lock and write lock are mutually exclusive
var rw sync.RWMutex
//Read lock and locking
rw.Rlock()
//Read lock and unlocking
rw.Runlock()
Read More:
- [Go] Solve the fatal error: concurrent map writes map is not concurrently safe
- How to Solve Go Error: concurrent map iteration and map write
- [Solved] Golang Error: fatal error: concurrent map writes
- Hash_map is deprecated and will be REMOVED. Please use unordered_map.
- [Solved] cocopod Error: failed: undefined method `map‘ for nil:NilClass
- [Solved] Searching for inspections failed: undefined method `map‘ for nil:NilClass“
- How to Solve Error: IncompleteElementException: Could not find result map…
- How to Solve Cordova integrates Gaode Map key error
- [Solved] IP Core Map Compile Error: Buffers of the same direction cannot beplaced in series.
- How to Solve Error: Missing type map configuration or unsupported mapping
- Failed to remove multipath map 320b508ca45022b80 [How to Solve]
- [Solved] Eclipse Connect Hadoop error: /An internal error occurred during: “Map/Reduce location status updater“
- Max virtual memory areas vm.max_map_count [65530] is too low, increase to at least
- Vue Import Baidu map error: BMap is not defined, eslint BMap reports an error
- [Solved] fatal: could not read Username for
- package golang.org/x/net/XXX: unrecognized import path “golang.org/x/net/xxx“…
- [Solved] Hystrix error: java.util.concurrent.TimeoutException: null
- How to Solve golang test Error: # command-line-arguments [command-line-arguments.test]
- Golang Error: go get github/xxx [How to Fix]
- [Go] Solve panic: runtime error: invalid memory address or nil pointer dereference in golang