Closed MarkZH closed 2 years ago
Not a Thread_Pool, but a Thread_Assembly_Line. A push_back
method creates a new std::future
which is put into an ordered container. This method blocks if there are no processes available to start it. The function passed to push_back()
is run within a lambda that also locks and releases one of a set of mutexes to limit the number of simultaneous threads. Perhaps the mutexes can be put in a queue that blocks when something tries to grab a mutex when it is empty.
For that last bit, use std::counting_semaphore
.
Actually, use std::counting_semaphore
in the current implementation of the gene pool to see how it simplifies the simultaneous game limit.
Simpler still: create a structure that acts like a ticketing system. Before starting a thread, take a ticket. Have the thread release the ticket when it finishes. This will be implemented in a class that wraps a std::condition_variable
for master. In c++20, that class will be deleted and replaced with a std::counting_semaphore
.
Thread limiter implemented here: 36dd6fcbd54f0975dc8be28d7f237765a96dc46a Work ongoing in multi-threaded-minimax branch
Full-minimax search on depth 2 moves is very slow due to having to traverse so much more of the game tree. Reduce this to depth one, maybe with a shared Alpha/Beta values.
More importantly, the engine crashes while doing multi-threaded search. The location of the crash is usually random with memory locations indicating destructed data or out-of-bounds access. Investigating ...
All data sent to threads is now copied as of commit 2d4062b91560c9e96269aaa65b85e09f447510ee
The multi-threading was reduced to depth one moves due to slowness induced by so much searching caused by the lessened effectiveness of alpha-beta pruning due to starting with new windows with every thread. The branch is fully functional and waiting to be merged.
Threads can now be used in gene pools as of eda7239c6f97fcaecbfd92601254649cb8129ddc
This can also be an attempt to do multi-threaded minimax with a thread pool similar to the gene pool structure for starting simultaneous games.
Might also be a good idea to create a Thread_Pool class to handle both these cases.