dsm13698679318 2015-05-07 18:04
浏览 59
已采纳

来自不同渠道的数据进入选择语句是否可以忽略?

Is it possible for data coming in through a channel in golang to get ignored if it is not caught at the right moment inside a select statement?

For example, lets say there is this select statement:

for {
    select {
    case <-timer.C:
        //block A
    default:
        // block B takes 2 seconds.
    }
}

If timer ends while block B is running, does block A still run in the next iteration of the loop or does the channel's incoming data get lost?

  • 写回答

1条回答 默认 最新

  • doudundian9558 2015-05-07 18:16
    关注

    When the timer expires, it will send the current time on C. If no one is reading from C at the time, the send will block, so it will wait until the value is received. In this case, it will wait till the next iteration of the loop.

    Channels are designed to be a synchronization mechanism, so they don't require readers and writers to be already synchronized.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器