mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-24 19:16:49 +08:00
Clarify the behaviour of execute_with_worker[s]
This commit is contained in:
@@ -186,8 +186,7 @@ void ThreadPool::clear() {
|
||||
main()->previousTimeReduction = 1.0;
|
||||
}
|
||||
|
||||
|
||||
void ThreadPool::execute_with_workers(std::function<void(Thread&)> worker)
|
||||
void ThreadPool::execute_with_workers(const std::function<void(Thread&)>& worker)
|
||||
{
|
||||
for(Thread* th : *this)
|
||||
{
|
||||
|
||||
11
src/thread.h
11
src/thread.h
@@ -52,7 +52,13 @@ public:
|
||||
explicit Thread(size_t);
|
||||
virtual ~Thread();
|
||||
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);
|
||||
|
||||
void clear();
|
||||
void idle_loop();
|
||||
void start_searching();
|
||||
@@ -109,7 +115,10 @@ struct MainThread : public 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 clear();
|
||||
|
||||
Reference in New Issue
Block a user