1
0
mirror of https://github.com/golang/go synced 2024-11-25 03:57:56 -07:00

gc: fix pprof deadlock

Fixes #2051.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/4834041
This commit is contained in:
Russ Cox 2011-07-28 21:03:40 -04:00
parent 032ffb2e90
commit bed7e3ed78
2 changed files with 17 additions and 4 deletions

View File

@ -122,6 +122,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)
hz = 0; hz = 0;

View File

@ -420,10 +420,19 @@ runtime·findfunc(uintptr addr)
Func *f; Func *f;
int32 nf, n; int32 nf, n;
// Use atomic double-checked locking,
// because when called from pprof signal
// handler, findfunc must run without
// 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); runtime·lock(&funclock);
if(func == nil) if(func == nil)
buildfuncs(); buildfuncs();
runtime·unlock(&funclock); runtime·unlock(&funclock);
}
if(nfunc == 0) if(nfunc == 0)
return nil; return nil;