3 ms·
I don't know about sync.Map, but many concurrent maps don't require any locking (or require rarely). Protecting map with a lock is a very naive solution, it'll
by vardump 7y ago
I don't know about sync.Map, but many concurrent maps don't require any locking (or require rarely).
Protecting map with a lock is a very naive solution, it'll perform badly with a lot of concurrent writes.
- erik_seaberg 7y agohttps://golang.org/src/sync/map.go https://golang.org/src/sync/map.go is not completely lock-free but yeah, I think it's trying to batch structural changes to the map (and atomic compare-and-set on existing entries) which isn't something I would rewrite casually. There's just no good reason that you can't reuse it without rewriting all call sites. []T and map[K]V and chan T should implement interfaces, everyone should always use those interfaces, and monomorphization should skip the runtime dispatch.