当前位置:网站首页>go channel简单笔记
go channel简单笔记
2022-07-25 17:36:00 【kankan231】
go的通道用于goroutine之间的通信与数据同步,是go中比较重要的类型之一
nil通道:
未使用make进行初始化的chan默认值为nil,读取/写入nil通道会永久阻塞当前协程,关闭nil通道会panic
无缓冲通道:
使用make初始化通道时未指定数量则为无缓冲通道,必须读写双方同时操作才不会阻塞,有读无写时,读将阻塞,有写无读时,写将阻塞
有缓冲通道:
使用make初始化通道时指定数量则为有缓冲通道,当缓冲区未满时,写入将不会阻塞,否则阻塞;当缓冲区有数据时,读取不会阻塞,否则阻塞
已关闭通道:
使用close(ch)关闭通道后,读取该通道将立即返回该通道类型的零值,写入已关闭的通道将会panic
在使用通道时,应注意操作通道时阻塞造成的协程无法退出问题,从而导致内存泄漏
边栏推荐
猜你喜欢

Using rank to discuss the solution of linear equations / the positional relationship of three planes

第三章、数据类型和变量

食品安全 | 八问八答带你重新认识小龙虾!这样吃才对!

11. Camera and lens

Technical difficulties and applications of large humanoid robots

STM32 PAJ7620U2手势识别模块(IIC通信)程序源码详解
Go language series: where does go come from and where will go?
![[solution] the Microsoft edge browser has the problem of](/img/47/7e20a4f1e04577153e7cf0a6c61f26.png)
[solution] the Microsoft edge browser has the problem of "unable to access this page"

8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇

"Digital security" alert NFT's seven Scams
随机推荐
交友活动记录
Headless mode of new selenium4.3 in egde browser
Redis cluster deployment based on redis6.2.4
Thesis reading_ Multi task learning_ MMoE
【Cadence Allegro PCB设计】error: Possible pin type conflict GND/VCC Power Connected to Output
Step by step introduction of sqlsugar based development framework (13) -- package the upload component based on elementplus, which is convenient for the project
EasyUI modification and DataGrid dialog form control use
计算日期或日期格式化
Redis源码与设计剖析 -- 18.Redis网络连接库分析
02. Add two numbers
生成扩散模型漫谈:DDPM = 贝叶斯 + 去噪
Google Earth engine - download the globalmlbuildingfootprints vector collection of global buildings
WPF implements user avatar selector
8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
OSPF---开放式最短优先路径协议
Chapter 4: operators
04. Find the median of two positive arrays
EasyUI drop-down box, add and put on and off shelves of products
多项式相加
Calculation date or date formatting