mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
sync: yield to the waiter when unlocking a starving mutex
When we have already assigned the semaphore ticket to a specific waiter, we want to get the waiter running as fast as possible since no other G waiting on the semaphore can acquire it optimistically. The net effect is that, when a sync.Mutex is contented, the code in the critical section guarded by the Mutex gets a priority boost. Fixes #33747 Change-Id: I9967f0f763c25504010651bdd7f944ee0189cd45 Reviewed-on: https://go-review.googlesource.com/c/go/+/200577 Reviewed-by: Rhys Hiltner <rhys@justin.tv> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
3eabdd291d
commit
a8f57f4ada
5 changed files with 125 additions and 2 deletions
|
|
@ -730,3 +730,11 @@ func RunGetgThreadSwitchTest() {
|
|||
panic("g1 != g3")
|
||||
}
|
||||
}
|
||||
|
||||
var Semacquire = semacquire
|
||||
var Semrelease1 = semrelease1
|
||||
|
||||
func SemNwait(addr *uint32) uint32 {
|
||||
root := semroot(addr)
|
||||
return atomic.Load(&root.nwait)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue