2 ms·
Version 1.9 introduced the sync.Map https://golang.org/pkg/sync/#Map https://golang.org/pkg/sync/#Map Would using a sync.WaitGroup and closure be wrong? Is mut
by gophergopher 8y ago
Version 1.9 introduced the sync.Map
https://golang.org/pkg/sync/#Map https://golang.org/pkg/sync/#Map
Would using a sync.WaitGroup and closure be wrong?
Is mutex better for shared memory?
- jzelinskie 8y agosync.Map is NOT a good solution for all concurrent map use cases. Please use your best judgement for the well documented trade-offs: >The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.