From 1d19a72bf39744158458222dc01588005787af25 Mon Sep 17 00:00:00 2001 From: Kevin Huck Date: Wed, 10 Apr 2024 13:18:52 -0700 Subject: [PATCH] Removing sleep during shutdown if the background thread is already done. --- src/apex/proc_read.cpp | 4 ++++ src/apex/proc_read.h | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/apex/proc_read.cpp b/src/apex/proc_read.cpp index a4f4d961..c23de038 100644 --- a/src/apex/proc_read.cpp +++ b/src/apex/proc_read.cpp @@ -834,6 +834,7 @@ namespace apex { break; } if (done) break; + reading = true; if (apex_options::use_tau()) { tau_listener::Tau_start_wrapper("proc_data_reader::read_proc: main loop"); } @@ -873,7 +874,10 @@ namespace apex { if (apex_options::use_tau()) { tau_listener::Tau_stop_wrapper("proc_data_reader::read_proc: main loop"); } + reading = false; } + // in case we broke from while loop + reading = false; #ifdef APEX_HAVE_LM_SENSORS delete(mysensors); #endif diff --git a/src/apex/proc_read.h b/src/apex/proc_read.h index 06e8d231..59884b5f 100644 --- a/src/apex/proc_read.h +++ b/src/apex/proc_read.h @@ -48,6 +48,7 @@ class proc_data_reader { private: //pthread_wrapper * worker_thread; std::atomic done; + std::atomic reading; std::thread worker_thread; std::condition_variable cv; std::mutex cv_m; @@ -61,7 +62,7 @@ class proc_data_reader { }; */ void* read_proc(void); - proc_data_reader(void) : done(false) { + proc_data_reader(void) : done(false), reading(false) { worker_thread = std::thread(&proc_data_reader::read_proc, this); worker_thread.detach(); } @@ -73,8 +74,10 @@ class proc_data_reader { if (worker_thread.joinable()) { worker_thread.join(); } - // this is helpful if we are sampling frequently - usleep(apex_options::proc_period()); + if(reading) { + // this is helpful if we are sampling frequently + usleep(apex_options::proc_period()); + } } ~proc_data_reader(void) {