示例#1
0
ThreadPool::~ThreadPool() {
	while(!joinComplete) {
		joinAll();
		Thread::mSleep(1);
	}
	this->m_mutex->lock();
	this->runFlag = false;
	this->m_mutex->unlock();

	m_mutex->lock();
	bool fl = this->complete;
	m_mutex->unlock();
	while(!fl)
	{
		m_mutex->lock();
		fl = this->complete;
		m_mutex->unlock();
		Thread::sSleep(1);
	}
	delete poller;
	delete wpool;
	for (int i = 0; i <(int)tpool->size(); i++) {
		delete tpool->at(i);
	}
	delete m_mutex;
	if(console)
	{
		logger << "Destroyed PoolThread Pool\n" << flush;
	}
}
示例#2
0
mt::ThreadGroup::~ThreadGroup()
{
    try
    {
        joinAll();
    }
    catch (...)
    {
        // Make sure we don't throw out of the destructor.
    }
}
示例#3
0
void Perft::run() {

    if (!load()) {
        perftRes.hash = nullptr;
        if (mbSize) {
            alloc();
        }
    }

    if (fen.empty()) {
        fen = STARTPOS;
    }
    if (!perftRes.depth) {
        perftRes.depth = 1;
    }
    if (!perftRes.nCpu) {
        perftRes.nCpu = 1;
    }
    PerftThread *p = new PerftThread();
    if (!fen.empty()) {
        p->loadFen(fen);
    }
    p->setPerft(true);
    int side = p->getSide() ? 1 : 0;
    p->display();
    cout << "fen:\t\t\t" << fen << endl;
    cout << "depth:\t\t\t" << perftRes.depth << endl;
    cout << "#cpu:\t\t\t" << perftRes.nCpu << endl;
    cout << "cache size:\t\t" << mbSize << endl;
    cout << "dump file:\t\t" << dumpFile << endl;
    cout << endl << Time::getLocalTime() << " start perft test..." << endl;

    Timer t2(minutesToDump * 60);
    if (perftRes.hash && !dumpFile.empty()) {
        signal(SIGINT, Perft::ctrlChandler);
        cout << "dump hash table in " << dumpFile << " every " << minutesToDump << " minutes" << endl;
        cout << "type 'dump' to dump now" << endl;
        t2.registerObservers([this]() {
            dump();
        });
        t2.start();
    }

    cout << endl << endl << setw(6) << "move" << setw(20) << "tot";
    cout << setw(8) << "#";
    cout << endl;

    time.resetAndStart();
    p->incListId();
    u64 friends = side ? p->getBitmap<WHITE>() : p->getBitmap<BLACK>();
    u64 enemies = side ? p->getBitmap<BLACK>() : p->getBitmap<WHITE>();
    p->generateCaptures(side, enemies, friends);
    p->generateMoves(side, friends | enemies);
    int listcount = p->getListSize();
    count = listcount;
    delete (p);
    p = nullptr;
    ASSERT(perftRes.nCpu > 0);
    int block = listcount / perftRes.nCpu;
    int i, s = 0;
    setNthread(perftRes.nCpu);
    for (i = 0; i < perftRes.nCpu - 1; i++) {
        PerftThread &perftThread = getNextThread();
        perftThread.setParam(fen, s, s + block, &perftRes);
        s += block;
    }
    PerftThread &perftThread = getNextThread();
    perftThread.setParam(fen, s, listcount, &perftRes);
    startAll();
    joinAll();
}
示例#4
0
mocca::RunnableGroup::~RunnableGroup() {
    joinAll();
}