Revert "maybe fixed crashes | bench 1801941"

This reverts commit 64b2e3d9b1.
This commit is contained in:
rektdie committed 2026-02-24 23:39:59 +01:00
1 parent 64b2e3d9b1
commit 079959e6d4
5 files changed
+28 -60

No files matched your search

+8 -38
View File
@@ -4,7 +4,6 @@
#include <string>
#include <tuple>
#include <memory>
#include <vector>
#include "types.h"
#include "movegen.h"
#include "search.h"
@@ -89,38 +88,27 @@ static double ReadParam(const std::string& param, const std::string &command) {
#ifdef _WIN32
// Windows implementation using std::thread
static std::vector<std::thread> activeThreads;
template <SEARCH::searchMode mode>
static void ThreadFunc(Board board, SearchParams params, SEARCH::SearchContext* ctx) {
SEARCH::SearchPosition<mode>(board, params, ctx);
static void ThreadFunc(Board* board, SearchParams params, SEARCH::SearchContext* ctx) {
SEARCH::SearchPosition<mode>(*board, params, ctx);
delete ctx;
}
static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchContext* ctx, int id) {
std::thread searchThread;
SEARCH::SearchContext* ctxCopy = new SEARCH::SearchContext(*ctx);
if (id == 0)
ctxCopy->doPrint = true;
if (params.nodes) {
activeThreads.emplace_back(ThreadFunc<SEARCH::nodesMode>, board, params, ctxCopy);
searchThread = std::thread(ThreadFunc<SEARCH::nodesMode>, &board, params, ctxCopy);
} else {
activeThreads.emplace_back(ThreadFunc<SEARCH::normal>, board, params, ctxCopy);
searchThread = std::thread(ThreadFunc<SEARCH::normal>, &board, params, ctxCopy);
}
}
static void WaitForSearchThreads() {
for (auto &thread : activeThreads) {
if (thread.joinable()) {
thread.join();
}
}
activeThreads.clear();
searchThread.detach();
}
#else
// Unix/Linux implementation using pthread
static std::vector<pthread_t> activeThreads;
template <SEARCH::searchMode mode>
static void* ThreadFunc(void* arg) {
auto* tup = static_cast<std::tuple<Board, SearchParams, SEARCH::SearchContext*>*>(arg);
@@ -150,22 +138,10 @@ static void StartSearchThread(Board& board, SearchParams params, SEARCH::SearchC
}
pthread_attr_destroy(&attr);
activeThreads.push_back(thread);
}
static void WaitForSearchThreads() {
for (pthread_t thread : activeThreads) {
pthread_join(thread, nullptr);
}
activeThreads.clear();
pthread_detach(thread);
}
#endif
static void StopAndWaitForSearchThreads() {
searchStopped.store(true, std::memory_order_relaxed);
WaitForSearchThreads();
}
static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext* ctx) {
SearchParams params;
@@ -184,8 +160,6 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext* c
params.btime = 99999999;
}
StopAndWaitForSearchThreads();
for (int i = 0; i < threads; i++) {
StartSearchThread(board, params, ctx, i);
}
@@ -193,14 +167,12 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext* c
static void SetOption(std::string& command, SEARCH::SearchContext* ctx) {
if (command.find("Hash") != std::string::npos) {
StopAndWaitForSearchThreads();
U64 hashSize = (ReadParam("value", command) * 1000000ULL) / sizeof(TTEntry);
ctx->TT->Resize(hashSize);
return;
}
if (command.find("Threads") != std::string::npos) {
StopAndWaitForSearchThreads();
threads = ReadParam("value", command);
return;
}
@@ -284,7 +256,6 @@ void UCILoop(Board &board) {
// parse UCI "ucinewgame" command
if (input.find("ucinewgame") != std::string::npos) {
StopAndWaitForSearchThreads();
board.SetByFen(StartingFen);
// Clearing
@@ -308,7 +279,6 @@ void UCILoop(Board &board) {
// parse UCI "quit" command
if (input.find("quit") != std::string::npos) {
StopAndWaitForSearchThreads();
// stop the loop
break;
}
@@ -316,7 +286,7 @@ void UCILoop(Board &board) {
// parse UCI "stop" command
if (input.find("stop") != std::string::npos) {
// stop the loop
StopAndWaitForSearchThreads();
searchStopped = true;
continue;
}