thead: 彻底去掉 QThread

已知问题:刚启动UI就自动下了2子。
This commit is contained in:
Calcitem 2020-10-03 10:41:05 +08:00
parent 0d5667f8de
commit ffbc18b30a
4 changed files with 12 additions and 13 deletions

View File

@ -36,7 +36,7 @@ Value MTDF(Position *pos, Sanmill::Stack<Position> &ss, Value firstguess, Depth
AiThread::AiThread(int color, QObject *parent) :
stdThread(&AiThread::idle_loop, this),
QThread(parent),
QObject(parent),
timeLimit(3600)
{
this->us = color;
@ -172,7 +172,7 @@ void AiThread::idle_loop() // idle_loop()
void AiThread::act()
{
if (isFinished() || !isRunning())
if (exit|| !searching)
return;
std::lock_guard<std::mutex> lk(mutex);

View File

@ -22,7 +22,6 @@
#include <condition_variable>
#include <mutex>
#include <QThread>
#include <QTimer>
#include "position.h"
#include "search.h"
@ -32,11 +31,11 @@
#include "position.h"
#include "thread_win32_osx.h"
class AiThread : public QThread
class AiThread : public QObject
{
Q_OBJECT
private:
public:
std::mutex mutex;
std::condition_variable cv;
bool exit = false, searching = true; // Set before starting std::thread

View File

@ -352,10 +352,10 @@ void GameController::setEngine(int color, bool arg)
if (arg) {
aiThread[color]->setAi(&position);
if (aiThread[color]->isRunning())
if (aiThread[color]->searching)
aiThread[color]->start_searching();
else
aiThread[color]->start();
aiThread[color]->start_searching();
} else {
aiThread[color]->start_searching();
}

View File

@ -268,11 +268,11 @@ public slots:
void startAiThreads()
{
if (isAiPlayer[BLACK]) {
aiThread[BLACK]->start();
aiThread[BLACK]->start_searching();
}
if (isAiPlayer[WHITE]) {
aiThread[WHITE]->start();
aiThread[WHITE]->start_searching();
}
}
@ -280,11 +280,11 @@ public slots:
{
if (isAiPlayer[BLACK]) {
aiThread[BLACK]->start_searching();
aiThread[BLACK]->wait();
aiThread[BLACK]->wait_for_search_finished();
}
if (isAiPlayer[WHITE]) {
aiThread[WHITE]->start_searching();
aiThread[WHITE]->wait();
aiThread[WHITE]->wait_for_search_finished();
}
}
@ -296,8 +296,8 @@ public slots:
void waitThreads()
{
aiThread[BLACK]->wait();
aiThread[WHITE]->wait();
aiThread[BLACK]->wait_for_search_finished();
aiThread[WHITE]->wait_for_search_finished();
}
void stopAndWaitThreads()