首页 > 其他 > 详细

A Tour of Go Buffered Channels

时间:2014-10-29 01:41:18      阅读:248      评论:0      收藏:0      [点我收藏+]

Channels can be buffered. Provide the buffer length as the second argument to make to initialize a buffered channel:

ch := make(chan int, 100)

Sends to a buffered channel block only when the buffer is full. Receives block when the buffer is empty.

Modify the example to overfill the buffer and see what happens.

package main

import "fmt"

func main() {
    c := make(chan int, 2)
    c <- 1
    fmt.Println(<-c)
    fmt.Println(<-c)
}

 

A Tour of Go Buffered Channels

原文:http://www.cnblogs.com/ghgyj/p/4058315.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!