Comment by bloppe

4 days ago

Go famously summed up their preferred approach to shared state:

> Don't communicate by sharing memory; share memory by communicating.

Which they then failed to follow, especially since goroutines share memory with each other.

  • Go is a bit more of a low level language compared to actor languages where the language enforces that programming model. I think the point of the slogan is that you want to make the shared memory access an implementation detail of your larger system.

  • Threads share the same memory by definition, though. When you isolate these threads from a memory PoV, they become processes.

    Moreover, threads are arguably useless without shared memory anyway. A thread is invoked to work on the same data structure with multiple "affectors". Coordination of these affectors is up to you. Atomics, locks, queues... The tools are many.

    In fact, processes are just threads which are isolated from each other, and this isolation is enforced by the processor.

    • Goroutines aren't posix threads. They could've lacked shared memory by default, which could be enforced by a combination of the compiler and runtime like with Erlang.

  • Who is "they"? This isn't Rust. It's still up to the developer to follow the advice.

    Anyway, I would stop short of saying "Go chose shared memory". They've always been clear that that's plan B.

    • Go's creators said "Don't communicate by sharing memory", but then designed goroutines to do exactly that. It's quite hard to not share memory by accident, actually.

      It's not like it's a disaster, but it's certainly inconsistent.

      2 replies →