Commit bed7e3ed authored by Russ Cox's avatar Russ Cox

gc: fix pprof deadlock

Fixes #2051.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4834041
parent 032ffb2e
...@@ -121,6 +121,10 @@ runtime·SetCPUProfileRate(int32 hz) ...@@ -121,6 +121,10 @@ runtime·SetCPUProfileRate(int32 hz)
{ {
uintptr *p; uintptr *p;
uintptr n; uintptr n;
// Call findfunc now so that it won't have to
// build tables during the signal handler.
runtime·findfunc(0);
// Clamp hz to something reasonable. // Clamp hz to something reasonable.
if(hz < 0) if(hz < 0)
......
...@@ -420,10 +420,19 @@ runtime·findfunc(uintptr addr) ...@@ -420,10 +420,19 @@ runtime·findfunc(uintptr addr)
Func *f; Func *f;
int32 nf, n; int32 nf, n;
runtime·lock(&funclock); // Use atomic double-checked locking,
if(func == nil) // because when called from pprof signal
buildfuncs(); // handler, findfunc must run without
runtime·unlock(&funclock); // grabbing any locks.
// (Before enabling the signal handler,
// SetCPUProfileRate calls findfunc to trigger
// the initialization outside the handler.)
if(runtime·atomicloadp(&func) == nil) {
runtime·lock(&funclock);
if(func == nil)
buildfuncs();
runtime·unlock(&funclock);
}
if(nfunc == 0) if(nfunc == 0)
return nil; return nil;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment