2 ms·
> Can you share memory between cores with go without copying the memory? Yes. Go's "do not communicate by sharing memory; instead, share memory by communicatin
by scottlamb 7y ago
> Can you share memory between cores with go without copying the memory?
Yes. Go's "do not communicate by sharing memory; instead, share memory by communicating" thing [1] is advice, not a language requirement. Go's memory model is similar to C's. Channels are completely optional; you can share pointers and protect stuff with mutexes. You can skip the mutexes and have data races, too, unfortunately. At least Go has good tooling for finding these kinds of races dynamically. [2]
Rust is similar, except that it prevents data races (as well as other types of memory errors) in safe Rust code, barring compiler bugs. I absolutely love this property, and it can save you from very difficult-to-debug production problems. It has a significant upfront cost in terms of "fighting the borrow checker", adding extra annotations to your code, etc., so it's definitely not worth it for every developer in every situation.
[1] https://blog.golang.org/share-memory-by-communicating https://blog.golang.org/share-memory-by-communicating
[2] https://blog.golang.org/race-detector https://blog.golang.org/race-detector