From eacfb87624ad67a2c1a0a7fc1b512bf505362bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20V=C3=A4th?= Date: Mon, 27 Feb 2017 18:12:18 +0100 Subject: [PATCH] Speed up multithreading by avoiding superfluous waits when pruning --- ChangeLog | 3 +++ configure.ac | 2 +- src/chessproblem.cc | 14 ++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a75af85..9879ea1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ # ChangeLog for chessproblem +*chessproblem-2.4 + - Speed up multithreading by avoiding superfluous waits when pruning + *chessproblem-2.3 - Rename PushGuard->push_guard and PushGuardDisarmable->unique_push in analogy to std::lock_guard and std::unique_lock. diff --git a/configure.ac b/configure.ac index 896ce48..1d2b909 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ # Martin V\"ath dnl keep version in same line as AC_INIT for possible usage in scripts -AC_INIT([chessproblem], [2.3], +AC_INIT([chessproblem], [2.4], [https://github.com/vaeth/chessproblem/issues/], [chessproblem], [https://github.com/vaeth/chessproblem/]) diff --git a/src/chessproblem.cc b/src/chessproblem.cc index e9bc9ae..10b2712 100644 --- a/src/chessproblem.cc +++ b/src/chessproblem.cc @@ -532,12 +532,18 @@ void ChessProblem::SolverThread(chessproblem::Communicate *communicate, if (SingleThreadedMode()) { // Only a shortcut return; } - for (auto& t : threads) { - t.join(); - } if (subthread) { // We are at the end of a subthread delete field; - DecreaseThreads(); + DecreaseThreads(); // We might be not ready, but we will only wait + } + if (communicate->GotSignal()) { + for (auto& t : threads) { // No need to wait for exiting threads + t.detach(); + } + } else { + for (auto& t : threads) { + t.join(); + } } } #endif // NO_CHESSPROBLEM_THREADS