Wen Wei
unread,Mar 23, 2024, 2:58:43 PM3/23/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Lock always calls runtime_SemacquireMutex(&m.sema, queueLifo, 1) -> semacquire1 when in starving mode.
```go
// src/runtime/sema.go
func semacquire1(addr *uint32, lifo bool, profile semaProfileFlags, skipframes int, reason waitReason) {
gp := getg()
if gp != gp.m.curg {
throw("semacquire not on the G stack")
}
// Easy case.
if cansemacquire(addr) {
return
}
// ...
}
func semrelease1(addr *uint32, handoff bool, skipframes int) {
root := semtable.rootFor(addr)
atomic.Xadd(addr, 1) // The semaphore released here may be immediately contended for by goroutines of other threads calling semacquire1.
}
```
Does a new goroutine immediately acquire the lock instead of queuing fairly when in starving mode?