BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
Thread.hpp
Go to the documentation of this file.
1/*
2 * ======================================================================================
3 *
4 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░▒▓████████▓▒░
5 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
6 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
7 * ░▒▓███████▓▒░░▒▓██████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
8 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
9 * ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
10 * ░▒▓███████▓▒░░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░ ░▒▓█▓▒░
11 *
12 * ======================================================================================
13 */
14
19
20#pragma once
21
22#include <atomic>
23#include <chrono>
27#include <thread>
28
29namespace chess::uci {
30struct GoCommandOptions;
31} // namespace chess::uci
32
33namespace ben_bot::search {
34
35using std::chrono::milliseconds;
36
41struct Thread final {
43 Thread() = default;
44
48 explicit Thread(Callbacks&& callbacksToUse);
49
51
52 Thread(const Thread&) = delete;
53 Thread& operator=(const Thread&) = delete;
54 Thread(Thread&&) = delete;
55 Thread& operator=(Thread&&) = delete;
56
62
67 void start()
68 {
69 context.wait(); // shouldn't have been searching, but better safe than sorry
70
71 startSearch.store(true, std::memory_order::release);
72 }
73
74private:
75 void thread_func();
76
77 std::thread searcherThread { [this] { thread_func(); } };
78
79 std::atomic_bool threadShouldExit { false };
80 std::atomic_bool startSearch { false };
81};
82
83} // namespace ben_bot::search
Thread & operator=(const Thread &)=delete
Thread & operator=(Thread &&)=delete
Thread(Thread &&)=delete
Thread(const Thread &)=delete
Thread(Callbacks &&callbacksToUse)