From bd1105aa5a550224b1655ad38fcac60546df8a92 Mon Sep 17 00:00:00 2001 From: sdong Date: Mon, 19 May 2014 14:25:11 -0700 Subject: [PATCH] Print out thread ID while thread terminates for decreased pool size. Summary: Per request from @nkg-, temporarily print thread ID when a thread terminates. It is a temp solution as we try to minimized stderr messages. Test Plan: env_test Reviewers: haobo, igor, dhruba Reviewed By: igor CC: nkg-, leveldb Differential Revision: https://reviews.facebook.net/D18753 --- util/env_posix.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index 52787517a5..7ffba6f538 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -1479,8 +1479,7 @@ class PosixEnv : public Env { // Always terminate the running thread that is added last, even if there are // more than one thread to terminate. bool IsLastExcessiveThread(size_t thread_id) { - return HasExcessiveThread() && - thread_id == bgthreads_.size() - 1; + return HasExcessiveThread() && thread_id == bgthreads_.size() - 1; } // Is one of the threads to terminate. @@ -1505,13 +1504,18 @@ class PosixEnv : public Env { // Current thread is the last generated one and is excessive. // We always terminate excessive thread in the reverse order of // generation time. - pthread_detach(bgthreads_.back()); + auto terminating_thread = bgthreads_.back(); + pthread_detach(terminating_thread); bgthreads_.pop_back(); if (HasExcessiveThread()) { // There is still at least more excessive thread to terminate. WakeUpAllThreads(); } PthreadCall("unlock", pthread_mutex_unlock(&mu_)); + // TODO(sdong): temp logging. Need to help debugging. Remove it when + // the feature is proved to be stable. + fprintf(stdout, "Bg thread %zu terminates %llx\n", thread_id, + static_cast(terminating_thread)); break; } void (*function)(void*) = queue_.front().function;