dongqia3502 2016-06-07 22:50 采纳率: 100%
浏览 50
已采纳

在golang中创建一块缓冲通道

I couldn't find a way to create a slice of buffered channels in golang. I know how to create slice of unbuffered channel given as below

type ch chan int
channels := make([]ch,5)
  • 写回答

1条回答 默认 最新

  • douao8353 2016-06-07 22:57
    关注

    This statement channels := make([]ch,5) is simply allocating the container (the slice of channels which has a length of 5). In addition to that you have to initialize each channel individually which is when you would declare them as buffered rather than unbuffered. So extending your example just do this:

    for i, _ := range channels {
         channels[i] = make(chan int, BufferSize)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退