Re:Go Things I Love: Channels and Goroutines
by iamjfu on Tuesday January 07, 2020 @08:52AM
(#21979853)
TIL. That's a huge flaw. Thanks so much for your response!
[ Parent
| on HN ]
Re:Go Things I Love: Channels and Goroutines
by modernerd on Tuesday January 07, 2020 @09:33AM
(#21980211)
Welcome! It's the same for other data structures, by the way (not just slices) — maps are not safe for concurrent writes either. (The rationale seems to be that users of the data types can choose whether to make them safe for concurrent use or not depending on the use case.)
I found this helpful: https://youtu.be/29LLRKIL_TI?t=1340
Re:Go Things I Love: Channels and Goroutines
by irq-1 on Tuesday January 07, 2020 @11:13AM
(#21981319)
They added sync.Map
> Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.
Re:Go Things I Love: Channels and Goroutines
by masklinn on Tuesday January 07, 2020 @11:10AM
(#21981281)
> The rationale seems to be that users of the data types can choose whether to make them safe for concurrent use or not depending on the use case.
Also that for most uses a concurrent map is way overkill, and a thread-safe one is both costly and basically useless (hence the Java folks not keeping the thread-safety when migrating from Hashtable to HashMap).
On the other hand they're kinda shit given how awful non-builtin data structures are in Go, and how easy it is to "leak" maps between goroutines.