Clarify the behaviour of execute_with_worker[s]

This commit is contained in:
Tomasz Sobczyk
2020-10-20 10:50:59 +02:00
committed by nodchip
parent 74af287637
commit f2ad307de3
2 changed files with 11 additions and 3 deletions
+1 -2
View File
@@ -186,8 +186,7 @@ void ThreadPool::clear() {
main()->previousTimeReduction = 1.0; main()->previousTimeReduction = 1.0;
} }
void ThreadPool::execute_with_workers(const std::function<void(Thread&)>& worker)
void ThreadPool::execute_with_workers(std::function<void(Thread&)> worker)
{ {
for(Thread* th : *this) for(Thread* th : *this)
{ {
+10 -1
View File
@@ -52,7 +52,13 @@ public:
explicit Thread(size_t); explicit Thread(size_t);
virtual ~Thread(); virtual ~Thread();
virtual void search(); virtual void search();
// The function object to be executed is taken by value to remove
// the need for separate lvalue and rvalue overloads.
// The worker thread needs to have ownership of the task
// to be executed because otherwise there's no way to manage its lifetime.
virtual void execute_with_worker(std::function<void(Thread&)> t); virtual void execute_with_worker(std::function<void(Thread&)> t);
void clear(); void clear();
void idle_loop(); void idle_loop();
void start_searching(); void start_searching();
@@ -109,7 +115,10 @@ struct MainThread : public Thread {
struct ThreadPool : public std::vector<Thread*> { struct ThreadPool : public std::vector<Thread*> {
void execute_with_workers(std::function<void(Thread&)> worker); // Each thread gets its own copy of the `worker` function object.
// This means that each worker thread will have exclusive access
// to the state of the `worker` function object.
void execute_with_workers(const std::function<void(Thread&)>& worker);
void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false); void start_thinking(Position&, StateListPtr&, const Search::LimitsType&, bool = false);
void clear(); void clear();