3 ms·
With Go, the programmer will typically not be using data structures that are concurrently accessed from multiple goroutines. It is considered more idiomatic to
by ansible 13y ago
With Go, the programmer will typically not be using data structures that are concurrently accessed from multiple goroutines. It is considered more idiomatic to have one goroutine controlling a given data structure, and have the others communicate with it via channels.
- pron 13y agoThat approach has vastly different performance characteristics.
- jamra 13y agoThat is only one way of doing things. Even though channels facilitate that method, it is not unidiomatic to not use them. Channels are a way of queueing work, which is great for many use cases. You can use mutexes and shared memory if your situation calls for it. For example, if I am doing a graph traversal concurrently, I can use channels to send the work to many listening threads as I traverse that graph synchronously. If for some reason, I need to update that graph's representation asynchronously, I may need to use mutexes to lock the graph since the graph is now shared memory.