Explain: Don't communicate by sharing memory; share memory by communicating

前端 未结 6 1294
生来不讨喜
生来不讨喜 2020-12-13 02:50

I wonder what is the most down to earth explanation of this famous quote:

Don\'t communicate by sharing memory; share memory by communicating. (R. Pik

6条回答
  •  醉梦人生
    2020-12-13 03:42

    I don't think so. The gist is instead of protecting one fixed memory address with a lock or other concurrent primitives, you can architect the program in a way that only one stream of execution is allowed to access this memory by design.

    The easy way to achieve this is to share the reference to the memory by channels. Once you send the reference over the channel you forget it. In this way only the routine that will consume that channel will have access to it.

提交回复
热议问题