How you can write simple, reliable, and efficient user code (https://golang.org) if using your favored concurrency model results in race conditions?
How you can write simple, reliable, and efficient user code (https://golang.org) if using your favored concurrency model results in race conditions?
You can't. And the language is not expressive enough to be able to write generic immutable data structures as you have in Scala/Java/Kotlin/etc.
I think with 1 sender and 1 receiver the common solution in Rust is the same, to copy (or maybe move) the values sent... the type system provides some safety guarantees but I doubt it would be much different for performance. You wouldn't be able to send an immutable reference over a channel in Rust, since the compiler wouldn't know where the reference's lifetime ends. You could resort to refcounting, but you would probably only put in the effort if the data structure was large enough that copying was prohibitively expensive.
Same thing applies to the STM "subset" of Haskell -- conformance to which is statically verified by the type checker[1].
[1] There's no particular magic going on wrt. checking -- STM is a monad. It just happens to have "magic" runtime support.