码迷,mamicode.com
首页 > 其他好文 > 详细

[GO]channel

时间:2018-09-19 10:19:33      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:type   nbsp   创建   通过   传递   通道   引用   使用   同步   

goroutine运行在相同的地址空间,因此访问共享内存必须 做好同步。goroutine奉行通过通信来共享内存,而不是共享内存通信

它跟map一样,使用make来创建,它是一个引用 ,而不是值传递

make(chan Type, capacity)

channel <- value //发送value到channel

<- channel  //接收并将其丢弃

x := <-channel  //从channel中接收数据,并赋值给x

x, ok := <-channel //功能同上,同时检查通道是否已关闭或者是否为空

[GO]channel

标签:type   nbsp   创建   通过   传递   通道   引用   使用   同步   

原文地址:https://www.cnblogs.com/baylorqu/p/9672786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!