- 博客(1)
- 收藏
- 关注
原创 golang mutex
golang中的锁是通过CAS原子操作实现的,Mutex结构如下: type Mutex struct { state int32 semauint32 } //state表示锁当前状态,每个位都有意义,零值表示未上锁 //sema用做信号量,通过PV操作从等待队列中阻塞/唤醒goroutine,等待锁的goroutine会挂到等待队列中,并且陷入睡眠不被调度,unlock锁时才唤醒。具体在sync/mutex.go Lock函数实现中。...
2021-06-08 16:21:36
353
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人