From 81b498bc159d675014aaf89b56a341c1b2dffd46 Mon Sep 17 00:00:00 2001 From: Chilledheart Date: Thu, 22 May 2014 01:24:42 +0800 Subject: [PATCH] Print pthread_t in a more safe way --- util/env_posix.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index 7ffba6f53..1f8c3bcf2 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -94,6 +94,17 @@ static Status IOError(const std::string& context, int err_number) { return Status::IOError(context, strerror(err_number)); } +// TODO(sdong): temp logging. Need to help debugging. Remove it when +// the feature is proved to be stable. +inline void PrintThreadInfo(size_t thread_id, pthread_t id) { + unsigned char* ptc = (unsigned char*)(void*)(&id); + fprintf(stdout, "Bg thread %zu terminates 0x", thread_id); + for (size_t i = 0; i < sizeof(id); i++) { + fprintf(stdout, "%02x", (unsigned)(ptc[i])); + } + fprintf(stdout, "\n"); +} + #ifdef NDEBUG // empty in release build #define TEST_KILL_RANDOM(rocksdb_kill_odds) @@ -1514,8 +1525,7 @@ class PosixEnv : public Env { 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)); + PrintThreadInfo(thread_id, terminating_thread); break; } void (*function)(void*) = queue_.front().function;