Refactor threading run (#1961)
* ThreadManager::WaitForAllThreads removed
* WaitForAllThreads was only called either in single threaded
environments or just before all threads are joined anyway. As this
doesn't add a useful synchronization point, it's removed.
* Formatting issue
* Thread Sanitizer satisfied
* More formatting issues
diff --git a/src/benchmark_runner.cc b/src/benchmark_runner.cc
index b062c7c..55ad69c 100644
--- a/src/benchmark_runner.cc
+++ b/src/benchmark_runner.cc
@@ -302,7 +302,6 @@
/*profiler_manager=*/nullptr);
// The main thread has finished. Now let's wait for the other threads.
- manager->WaitForAllThreads();
for (std::thread& thread : pool) {
thread.join();
}
@@ -434,7 +433,6 @@
RunInThread(&b, memory_iterations, 0, manager.get(),
perf_counters_measurement_ptr,
/*profiler_manager=*/nullptr);
- manager->WaitForAllThreads();
manager.reset();
b.Teardown();
MemoryManager::Result memory_result;
@@ -450,7 +448,6 @@
RunInThread(&b, profile_iterations, 0, manager.get(),
/*perf_counters_measurement_ptr=*/nullptr,
/*profiler_manager=*/profiler_manager);
- manager->WaitForAllThreads();
manager.reset();
b.Teardown();
}
diff --git a/src/thread_manager.h b/src/thread_manager.h
index 819b3c4..a0ac37a 100644
--- a/src/thread_manager.h
+++ b/src/thread_manager.h
@@ -11,30 +11,15 @@
class ThreadManager {
public:
- explicit ThreadManager(int num_threads)
- : alive_threads_(num_threads), start_stop_barrier_(num_threads) {}
+ explicit ThreadManager(int num_threads) : start_stop_barrier_(num_threads) {}
Mutex& GetBenchmarkMutex() const RETURN_CAPABILITY(benchmark_mutex_) {
return benchmark_mutex_;
}
- bool StartStopBarrier() EXCLUDES(end_cond_mutex_) {
- return start_stop_barrier_.wait();
- }
+ bool StartStopBarrier() { return start_stop_barrier_.wait(); }
- void NotifyThreadComplete() EXCLUDES(end_cond_mutex_) {
- start_stop_barrier_.removeThread();
- if (--alive_threads_ == 0) {
- MutexLock lock(end_cond_mutex_);
- end_condition_.notify_all();
- }
- }
-
- void WaitForAllThreads() EXCLUDES(end_cond_mutex_) {
- MutexLock lock(end_cond_mutex_);
- end_condition_.wait(lock.native_handle(),
- [this]() { return alive_threads_ == 0; });
- }
+ void NotifyThreadComplete() { start_stop_barrier_.removeThread(); }
struct Result {
IterationCount iterations = 0;
@@ -51,10 +36,7 @@
private:
mutable Mutex benchmark_mutex_;
- std::atomic<int> alive_threads_;
Barrier start_stop_barrier_;
- Mutex end_cond_mutex_;
- Condition end_condition_;
};
} // namespace internal