解析Golang sync.Mutex源码-note

2022-12-19  本文已影响0人  robertzhai

代码路径

数据结构

// 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

上一篇 下一篇

猜你喜欢

热点阅读