summaryrefslogtreecommitdiff
path: root/src/pkg
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-07 23:16:12 -0400
committerRuss Cox <rsc@golang.org>2014-09-07 23:16:12 -0400
commit90c5cea2b2b7b969f57ba3a16c3de4ff34334fc3 (patch)
tree8c7bc8505300b1c939ccefdd85f9c5630e8134d1 /src/pkg
parent05a2ae05ebafd0bba48fe2e50ce332a5e3e2ed0e (diff)
downloadgo-90c5cea2b2b7b969f57ba3a16c3de4ff34334fc3.tar.gz
runtime: fix semacquire->acquireSudog->malloc->gogc->semacquire loop
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://codereview.appspot.com/135580043
Diffstat (limited to 'src/pkg')
-rw-r--r--src/pkg/runtime/proc.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/pkg/runtime/proc.go b/src/pkg/runtime/proc.go
index a9cac266b..48b8cbe39 100644
--- a/src/pkg/runtime/proc.go
+++ b/src/pkg/runtime/proc.go
@@ -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