]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix semacquire->acquireSudog->malloc->gogc->semacquire loop
authorRuss Cox <rsc@golang.org>
Mon, 8 Sep 2014 03:16:12 +0000 (23:16 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 8 Sep 2014 03:16:12 +0000 (23:16 -0400)
This is what broke the build at
http://build.golang.org/log/d9c6d334be16cbab85e99fddc6b4ba034319bd4e

LGTM=iant
R=golang-codereviews, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/135580043

src/pkg/runtime/proc.go

index a9cac266ba099d9d480ba691ba07a646d3aa532c..48b8cbe39451ac2d07bef688ac7e497915bcb284 100644 (file)
@@ -75,7 +75,19 @@ func acquireSudog() *sudog {
                c.sudogcache = s.next
                return s
        }
-       return new(sudog)
+
+       // Delicate dance: the semaphore implementation calls
+       // acquireSudog, acquireSudog calls new(sudog),
+       // new calls malloc, malloc can call the garbage collector,
+       // and the garbage collector calls the semaphore implementation
+       // in stoptheworld.
+       // Break the cycle by doing acquirem/releasem around new(sudog).
+       // The acquirem/releasem increments m.locks during new(sudog),
+       // which keeps the garbage collector from being invoked.
+       mp := acquirem()
+       p := new(sudog)
+       releasem(mp)
+       return p
 }
 
 //go:nosplit