From c7dc5e92ddb7c6d4e71edd7f24f9314e81a8413b Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 5 Sep 2019 15:43:32 -0400 Subject: [PATCH] test: tweak test to avoid unpreemptible loop with gccgo This test contains a very tight loop with locking/unlocking that can wind up as an unpreemptible when compiled with gccgo, depending on inlining. Tweak the test slightly to avoid this problem. Change-Id: I155fd2b4bfea961244eb6c6594c24ab03d32d41c Reviewed-on: https://go-review.googlesource.com/c/go/+/193619 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- misc/cgo/test/test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/misc/cgo/test/test.go b/misc/cgo/test/test.go index 4286fb9cdb..0a26bfb5cf 100644 --- a/misc/cgo/test/test.go +++ b/misc/cgo/test/test.go @@ -1950,11 +1950,20 @@ func test27660(t *testing.T) { // increase the likelihood that the race described in #27660 // results in corruption of ThreadSanitizer's internal state // and thus an assertion failure or segfault. + i := 0 for ctx.Err() == nil { j := rand.Intn(100) locks[j].Lock() ints[j]++ locks[j].Unlock() + // needed for gccgo, to avoid creation of an + // unpreemptible "fast path" in this loop. Choice + // of (1<<24) is somewhat arbitrary. + if i%(1<<24) == 0 { + runtime.Gosched() + } + i++ + } }() time.Sleep(time.Millisecond) -- 2.50.0