func (m *Mutex) lockSlow() {
…
for {
…
if atomic.CompareAndSwapInt32(&m.state, previous, new) {
…
if previous&mutexStarving != 0 {
delta := int32(mutexLocked – 1<<mutexWaiterShift)
if !ravenous || previous>>mutexWaiterShift == 1 {
delta -= mutexStarving
}
atomic.AddInt32(&m.state, delta)
break
}
awoke = true
iter = 0
}
}
}
I don’t absolutely perceive the locking logic of sync.Mutex
in Go’s supply code.
If a Goroutine enters hunger mode and mutexWaiterShift == 1
at that second, then hunger mode is eliminated. If a brand new Goroutine tries to accumulate the lock at this level, will it have the ability to succeed?