You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by ja...@apache.org on 2020/03/18 09:34:31 UTC

[incubator-brpc] branch master updated: not register pthread_atfork in child process

This is an automated email from the ASF dual-hosted git repository.

jamesge pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f8fc37  not register pthread_atfork in child process
2f8fc37 is described below

commit 2f8fc37d52c2a02ee6f348aaa52c7ded4a4844c3
Author: jamesge <jg...@gmail.com>
AuthorDate: Wed Mar 18 17:34:09 2020 +0800

    not register pthread_atfork in child process
---
 src/bvar/detail/sampler.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/bvar/detail/sampler.cpp b/src/bvar/detail/sampler.cpp
index fd49991..9ff91bf 100644
--- a/src/bvar/detail/sampler.cpp
+++ b/src/bvar/detail/sampler.cpp
@@ -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
@@ -88,7 +92,10 @@ private:
             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);
+            }
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org