Skip to content

Commit

Permalink
not register pthread_atfork in child process
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesge committed Mar 18, 2020
1 parent e3840c1 commit 2f8fc37
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bvar/detail/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ struct CombineSampler {
}
};

// True iff pthread_atfork was called. The callback to atfork works for child
// of child as well, no need to register in the child again.
static bool registered_atfork = false;

// Call take_sample() of all scheduled samplers.
// This can be done with regular timer thread, but it's way too slow(global
// contention + log(N) heap manipulations). We need it to be super fast so that
Expand Down Expand Up @@ -88,7 +92,10 @@ class SamplerCollector : public bvar::Reducer<Sampler*, CombineSampler> {
LOG(FATAL) << "Fail to create sampling_thread, " << berror(rc);
} else {
_created = true;
pthread_atfork(NULL, NULL, child_callback_atfork);
if (!registered_atfork) {
registered_atfork = true;
pthread_atfork(NULL, NULL, child_callback_atfork);
}
}
}

Expand Down

0 comments on commit 2f8fc37

Please sign in to comment.