美文网首页
解析Golang sync.Mutex源码-note

解析Golang sync.Mutex源码-note

作者: robertzhai | 来源:发表于2022-12-19 11:26 被阅读0次

代码路径

  • /usr/local/go/go17/src/sync/mutex.go

数据结构

// A Mutex is a mutual exclusion lock.
// The zero value for a Mutex is an unlocked mutex.
//
// A Mutex must not be copied after first use.
type Mutex struct {
    state int32   // mutex锁当前的状态
    sema  uint32  // 信号量,用于唤醒goroutine
}

// A Locker represents an object that can be locked and unlocked.
type Locker interface {
    Lock()
    Unlock()
}

lock

image.png

unlock

image.png

ref

相关文章

网友评论

      本文标题:解析Golang sync.Mutex源码-note

      本文链接:https://www.haomeiwen.com/subject/fxyyqdtx.html