golang channel buffer

package mainimport (    "fmt"    "time")func main() {    // Case-1: no buffer    //chanMessage := make(chan string)    // Case-2: with buffer ... the output changes    chanMessage := make(chan string, 2)    count := 4    go func() {        for i := 1; i 

buffer 2 表示能缓冲2个,实际上能send 3个。第4个才发生阻塞。
output:send messagesend messagesend messagemessage 1send messagemessage 2message 3message 4

+5level:2exp:10/50
上一篇:mysql备份sql,脚本


下一篇:聊聊并发(六)——ConcurrentLinkedQueue的实现原理分析