Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: How to poll stdin during thinking?

Author: Miguel A. Ballicora

Date: 08:37:02 12/12/01

Go up one level in this thread


On December 12, 2001 at 10:54:47, Severi Salminen wrote:

>Hi!
>
>How do you poll stdin during search? I just want to see if "quit" is sent to
>engine during search.  Otherwise my engine keeps searching even if WB has
>exited...
>
>And I don't know anything about multithreading. And I don't even wat to know ;)

After a long while I managed to solve this problem with multithreading.
The result is very clean.
I knew nothing about multithreading when I started and I know nothing now :-)
I am doing everything with two functions,
IIRC the spelling their names are _beginthreadex () and WaitForSingleObject()
One starts the thread and the other waits for it to be exited.
Communication the threads is through some global variables
ENGINE_STATE , STOP_FLAG, Analysis_mode, Skip_ponder.
ENGINE_STATE is an int variable that could have values THINKING, IDLE, MOVING,
PONDERING. I keep two positions, everytime I launch the engine thread I make a
copy of the position and I use the copy to "think". The other copy is visible
to the main thread and it is not modify so I can verify legality
of moves entered, print a diagram etc.

I am very happy with the result and I think that it is a very portable approach
since I need only two multithreading functions.

One important thing is that I had to organize very well my variables but it is
worth it since my code now looks much cleaner.

I managed to do it without critical sections, mutex and all those things
that I know little about since there are little interaction between the main
thread (the interface) and the engine thread.
For instance, to do move now I do
if (ENGINE_STATE == THINKING) {
STOP_FLAG = TRUE;
Skip_ponder = TRUE;
WaitForSingleObject(id);
}

The search checks once in while the state of STOP_FLAG along the timer.


Regards,
Miguel






>
>Severi



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.