Re:Another go at Go failed
by ansible on Wednesday January 08, 2014 @09:53AM
(#7023787)
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.
[ Parent
| on HN ]
That 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.