首页 > 其他 > 详细

channel底层实现

时间:2021-09-01 22:12:48      阅读:10      评论:0      收藏:0      [点我收藏+]
go:1.16

type hchan struct {
	qcount   uint           // chan里的元素数量
	dataqsiz uint           // chan底层循环数组长度
	buf      unsafe.Pointer // 指向底层循环数组指针,只针对有缓冲的channel
	elemsize uint16         // chan中元素大小
	closed   uint32         // chan是否被关闭
	elemtype *_type // chan中元素类型
	sendx    uint   // 已发送元素在循环列表中的索引
	recvx    uint   // 已接收元素在循环列表中的索引
	recvq    waitq  // 等待接收的goroutine队列
	sendq    waitq  // 等待发送的goroutine队列

	// lock protects all fields in hchan, as well as several
	// fields in sudogs blocked on this channel.
	//
	// Do not change another G‘s status while holding this lock
	// (in particular, do not ready a G), as this can deadlock
	// with stack shrinking.
	lock mutex // 保护hchan中的所有字段
}

  

channel底层实现

原文:https://www.cnblogs.com/why-blogs/p/15211441.html

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