Hacker News new | past | comments | ask | show | jobs | submit login

Yeah, I tend not to write or use these data structures. If I want a concurrent map, I usually write my own anyway. It’s easier to add the locks I want than to keep track of how sync.Map thinks about locking a map. I understand that this attitude angers a lot of people who believe that everything should be as DRY as possible, but this way works better for me.



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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: