Open dushaoshuai opened 1 year ago
如果关闭 channel 时,有因为发送操作而阻塞的 goroutine,channel 关闭后,他们会 panic^1。这是测试代码。
channel 关闭后,还向 channel 发送,会 panic,这个不用多说。
select
在 select 语句中,如果多个 case 中的交流都可进行,select 会(伪)随机选择其中的一个执行^3,随机的引入是为了避免饥饿问题。
case
channel 相关操作
个人认为需要注意的点
关闭 channel 与发送操作
如果关闭 channel 时,有因为发送操作而阻塞的 goroutine,channel 关闭后,他们会 panic^1。这是测试代码。
channel 关闭后,还向 channel 发送,会 panic,这个不用多说。
select
语句中的随机执行在
select
语句中,如果多个case
中的交流都可进行,select
会(伪)随机选择其中的一个执行^3,随机的引入是为了避免饥饿问题。参见