What's the point of one-way channels in Go?

前端 未结 3 1569
暖寄归人
暖寄归人 2020-12-12 23:25

I\'m learning Go and so far very impressed with it. I\'ve read all the online docs at golang.org and am halfway through Chrisnall\'s \"The Go Programming Language Phraseboo

3条回答
  •  不知归路
    2020-12-13 00:32

    Go channels are modelled on Hoare's Communicating Sequential Processes, a process algebra for concurrency that is oriented around event flows between communicating actors (small 'a'). As such, channels have a direction because they have a send end and a receive end, i.e. a producer of events and a consumer of events. A similar model is used in Occam and Limbo also.

    This is important - it would be hard to reason about deadlock issues if a channel-end could arbitrarily be re-used as both sender and receiver at different times.

提交回复
热议问题