runtime: have patience for trailing thread in contention test

The mutex contention profile tests have to create contention between OS
threads. Previously, the first thread to obtain the mutex under test
would busy-loop until it observed the other thread register its interest
in acquiring the mutex.

Slow builders (such as gotip-linux-arm and gotip-linux-amd64-noopt) are
timing out on this test. Have the leading thread yield to the OS when it
hasn't yet seen the contention, to give the other thread a better chance
to run.

For #70602
For #79409

Change-Id: I3f97e0739fd9cb06b939bfc7c1768ca5e027bd0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/779241
Auto-Submit: Rhys Hiltner <rhys.hiltner@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Bypass: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Rhys Hiltner 2026-05-18 09:31:26 -07:00 committed by Gopher Robot
parent b99b8feaae
commit 6c8731962d

View file

@ -1204,6 +1204,7 @@ func TestRuntimeLockMetricsAndProfile(t *testing.T) {
minTicks[role][n] = runtime.Cputicks() - t1
break
}
runtime.Usleep(uint32(1 + delayMicros/8))
}
runtime.Unlock(mu)
needContention.Store(int64(n - 1))