Skip to content

Commit 6b85fa8

Browse files
committed
runtime: iterate ms via allm linked list to avoid race
It's pointless to reach all ms via allgs, and doing so introduces a race, since the m member of a g can change underneath it. Instead iterate directly through the allm linked list. Updates: #31528 Updates: #34130 Change-Id: I34b88402b44339b0a5b4cd76eafd0ce6e43e2be1 Reviewed-on: https://go-review.googlesource.com/c/go/+/198417 Run-TryBot: Jason A. Donenfeld <[email protected]> Reviewed-by: Alex Brainman <[email protected]> Reviewed-by: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9e6a84f commit 6b85fa8

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/runtime/os_windows.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,11 @@ func monitorSuspendResume() {
277277
return // Running on Windows 7, where we don't need it anyway.
278278
}
279279
var fn interface{} = func(context uintptr, changeType uint32, setting uintptr) uintptr {
280-
lock(&allglock)
281-
for _, gp := range allgs {
282-
if gp.m != nil && gp.m.resumesema != 0 {
283-
stdcall1(_SetEvent, gp.m.resumesema)
280+
for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
281+
if mp.resumesema != 0 {
282+
stdcall1(_SetEvent, mp.resumesema)
284283
}
285284
}
286-
unlock(&allglock)
287285
return 0
288286
}
289287
params := _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS{

0 commit comments

Comments
 (0)