From b170c7e94c478e616d194af95caa7747d9fa4725 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 20 May 2025 15:56:43 -0700 Subject: runtime, internal/synctest, sync: associate WaitGroups with bubbles Add support to internal/synctest for managing associations between arbitrary pointers and synctest bubbles. (Implemented internally to the runtime package by attaching a special to the pointer.) Associate WaitGroups with bubbles. Since WaitGroups don't have a constructor, perform the association when Add is called. All Add calls must be made from within the same bubble, or outside any bubble. When a bubbled goroutine calls WaitGroup.Wait, the wait is durably blocking iff the WaitGroup is associated with the current bubble. Change-Id: I77e2701e734ac2fa2b32b28d5b0c853b7b2825c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/676656 Reviewed-by: Michael Knyszek Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Auto-Submit: Damien Neil --- src/runtime/runtime2.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/runtime/runtime2.go') diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 94ab87f6db..cd40586bc2 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -1096,6 +1096,7 @@ const ( waitReasonSynctestChanReceive // "chan receive (synctest)" waitReasonSynctestChanSend // "chan send (synctest)" waitReasonSynctestSelect // "select (synctest)" + waitReasonSynctestWaitGroupWait // "sync.WaitGroup.Wait (synctest)" waitReasonCleanupWait // "cleanup wait" ) @@ -1145,6 +1146,7 @@ var waitReasonStrings = [...]string{ waitReasonSynctestChanReceive: "chan receive (synctest)", waitReasonSynctestChanSend: "chan send (synctest)", waitReasonSynctestSelect: "select (synctest)", + waitReasonSynctestWaitGroupWait: "sync.WaitGroup.Wait (synctest)", waitReasonCleanupWait: "cleanup wait", } @@ -1190,18 +1192,18 @@ func (w waitReason) isIdleInSynctest() bool { // isIdleInSynctest indicates that a goroutine is considered idle by synctest.Wait. var isIdleInSynctest = [len(waitReasonStrings)]bool{ - waitReasonChanReceiveNilChan: true, - waitReasonChanSendNilChan: true, - waitReasonSelectNoCases: true, - waitReasonSleep: true, - waitReasonSyncCondWait: true, - waitReasonSyncWaitGroupWait: true, - waitReasonCoroutine: true, - waitReasonSynctestRun: true, - waitReasonSynctestWait: true, - waitReasonSynctestChanReceive: true, - waitReasonSynctestChanSend: true, - waitReasonSynctestSelect: true, + waitReasonChanReceiveNilChan: true, + waitReasonChanSendNilChan: true, + waitReasonSelectNoCases: true, + waitReasonSleep: true, + waitReasonSyncCondWait: true, + waitReasonSynctestWaitGroupWait: true, + waitReasonCoroutine: true, + waitReasonSynctestRun: true, + waitReasonSynctestWait: true, + waitReasonSynctestChanReceive: true, + waitReasonSynctestChanSend: true, + waitReasonSynctestSelect: true, } var ( -- cgit v1.3-5-g45d5