You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/07 15:02:00 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #12350: ARROW-15593: [C++] Fix a race condition in the thread pool

pitrou commented on a change in pull request #12350:
URL: https://github.com/apache/arrow/pull/12350#discussion_r800744882



##########
File path: cpp/src/arrow/util/thread_pool.cc
##########
@@ -235,23 +235,32 @@ ThreadPool::~ThreadPool() {
 void ThreadPool::ProtectAgainstFork() {
 #ifndef _WIN32
   pid_t current_pid = getpid();
-  if (pid_ != current_pid) {
-    // Reinitialize internal state in child process after fork()
-    // Ideally we would use pthread_at_fork(), but that doesn't allow
-    // storing an argument, hence we'd need to maintain a list of all
-    // existing ThreadPools.
-    int capacity = state_->desired_capacity_;
-
-    auto new_state = std::make_shared<ThreadPool::State>();
-    new_state->please_shutdown_ = state_->please_shutdown_;
-    new_state->quick_shutdown_ = state_->quick_shutdown_;
-
-    pid_ = current_pid;
-    sp_state_ = new_state;
-    state_ = sp_state_.get();
-
+  pid_t old_pid = pid_.load();
+  int capacity = 0;
+  if (current_pid != old_pid) {
+    // FIXME: It may get deadlock here if users fork processes while the parent runs
+    // in the middle of resetting states.

Review comment:
       FTR, I'm working on a better fix for this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org