douan4359 2018-01-09 18:47
浏览 26

了解缓冲通道的工作方式

Can someone explain to me how channels work in these scenerios:

  1. If a channel isn't buffered, if you send to a channel 2 messages when no message has been received yet, does it just block the app?

  2. If there is a buffer, it behaves like #1 once the bufferred amount is reached? So if the buffer is 2, after 2 messages it will just block until you recieve at least 1 message?

Since you have to set the bufferred amount, you can't just have a channel that stores an arbitrary amount of messages?

  • 写回答

1条回答 默认 最新

  • duan00529 2018-01-09 18:49
    关注
    1. Yes.
    2. Yes.
    3. No, you can't have an infinite-buffered channel.

    This is covered in detail in the Go tour.

    Basically, whenever a routine sends on a channel, that routine blocks until something is available to receive it. That may be the channel buffer, or it may be something trying to receive from the channel. Likewise, whenever a routine receives on a channel, that routine blocks until there is something for it to receive.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)