File tree 2 files changed +17
-4
lines changed 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,10 @@ runtime·SetCPUProfileRate(int32 hz)
121
121
{
122
122
uintptr * p ;
123
123
uintptr n ;
124
+
125
+ // Call findfunc now so that it won't have to
126
+ // build tables during the signal handler.
127
+ runtime·findfunc (0 );
124
128
125
129
// Clamp hz to something reasonable.
126
130
if (hz < 0 )
Original file line number Diff line number Diff line change @@ -420,10 +420,19 @@ runtime·findfunc(uintptr addr)
420
420
Func * f ;
421
421
int32 nf , n ;
422
422
423
- runtime·lock (& funclock );
424
- if (func == nil )
425
- buildfuncs ();
426
- runtime·unlock (& funclock );
423
+ // Use atomic double-checked locking,
424
+ // because when called from pprof signal
425
+ // handler, findfunc must run without
426
+ // grabbing any locks.
427
+ // (Before enabling the signal handler,
428
+ // SetCPUProfileRate calls findfunc to trigger
429
+ // the initialization outside the handler.)
430
+ if (runtime·atomicloadp (& func ) == nil ) {
431
+ runtime·lock (& funclock );
432
+ if (func == nil )
433
+ buildfuncs ();
434
+ runtime·unlock (& funclock );
435
+ }
427
436
428
437
if (nfunc == 0 )
429
438
return nil ;
You can’t perform that action at this time.
0 commit comments