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

前端 未结 6 1292
生来不讨喜
生来不讨喜 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条回答
  •  -上瘾入骨i
    2020-12-13 03:24

    Let me go simple and to the point here.

    Don't communicate by sharing memory.

    It is like when your are communicating using threads for example you have to use variables or mutexes to lock memory for not allowing someone to read and write on it until the communication is complete.

    Share memory by communicating

    In go routines values move on channels rather than blocking the memory, sender notifies receiver to receive from that channel and hence it share memory by communicating with receiver to get from a channel.

提交回复
热议问题