]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: iterate ms via allm linked list to avoid race
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 2 Oct 2019 08:05:46 +0000 (10:05 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 3 Oct 2019 15:55:39 +0000 (15:55 +0000)
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 <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/os_windows.go

index 567c567000da289d38c5c84290172e524a877868..34d0627fcbfe58c3faffd44b5f17e26ce678c636 100644 (file)
@@ -277,13 +277,11 @@ func monitorSuspendResume() {
                return // Running on Windows 7, where we don't need it anyway.
        }
        var fn interface{} = func(context uintptr, changeType uint32, setting uintptr) uintptr {
-               lock(&allglock)
-               for _, gp := range allgs {
-                       if gp.m != nil && gp.m.resumesema != 0 {
-                               stdcall1(_SetEvent, gp.m.resumesema)
+               for mp := (*m)(atomic.Loadp(unsafe.Pointer(&allm))); mp != nil; mp = mp.alllink {
+                       if mp.resumesema != 0 {
+                               stdcall1(_SetEvent, mp.resumesema)
                        }
                }
-               unlock(&allglock)
                return 0
        }
        params := _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS{