示例#1
0
 // ThreadsManager::set_timer() is used to set the timer to trigger after msec
 // milliseconds. If msec is 0 then timer is stopped.
 static internal void set_timer(int msec)
 {
     ThreadHelper.lock_grab(timer.sleepLock);
     timer.maxPly = msec;
     ThreadHelper.cond_signal(timer.sleepCond); // Wake up and restart the timer
     ThreadHelper.lock_release(timer.sleepLock);
 }
示例#2
0
        // ThreadsManager::wait_for_search_finished() waits for main thread to go to
        // sleep, this means search is finished. Then returns.
        internal static void wait_for_search_finished()
        {
            Thread t = main_thread();

            ThreadHelper.lock_grab(t.sleepLock);
            ThreadHelper.cond_signal(t.sleepCond); // In case is waiting for stop or ponderhit
            while (!t.do_sleep)
            {
                ThreadHelper.cond_wait(sleepCond, t.sleepLock);
            }
            ThreadHelper.lock_release(t.sleepLock);
        }
示例#3
0
        // Thread::main_loop() is where the main thread is parked waiting to be started
        // when there is a new search. Main thread will launch all the slave threads.
        internal void main_loop(ManualResetEvent initEvent)
        {
            // Initialize the TT here
            UInt32 ttSize = UInt32.Parse(OptionMap.Instance["Hash"].v);

            if (TT.size != ttSize)
            {
                TT.set_size(ttSize);
            }

            // Signal done
            initEvent.Set();

            while (true)
            {
                ThreadHelper.lock_grab(sleepLock);

                do_sleep     = true; // Always return to sleep after a search
                is_searching = false;

                while (do_sleep && !do_exit)
                {
                    ThreadHelper.cond_signal(Threads.sleepCond); // Wake up UI thread if needed
                    ThreadHelper.cond_wait(sleepCond, sleepLock);
                }

                ThreadHelper.lock_release(sleepLock);

                if (do_exit)
                {
                    return;
                }

                is_searching = true;

                Search.think(); // This is the search entry point
            }
        }
示例#4
0
 internal void wake_up()
 {
     ThreadHelper.lock_grab(sleepLock);
     ThreadHelper.cond_signal(sleepCond);
     ThreadHelper.lock_release(sleepLock);
 }