• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

ufufufu

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

channel底层实现

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中的所有字段
}

  

posted on 2021-08-31 17:35  ufufufu  阅读(65)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3