Author: Alessandro Scotti
Date: 13:22:01 08/29/04
Go up one level in this thread
On August 29, 2004 at 12:04:47, Uri Blass wrote:
>Do you have a waiting function in your code?
If necessary, I wait by releasing the rest of the main thread timeslice with
functions like Sleep(0) or sched_yield(). Using a synchronization object is
possible but I haven't decided if it's really necessary in this part. On the
other hand, I use a thread for reading input and there I always wait on some
object, otherwise I would waste some CPU time.
The main loop of my program looks like this:
while( ! done ) {
switch( state ) {
case state_Thinking:
think();
break;
case state_Pondering:
ponder();
break;
case state_PonderMissed:
// Go directly to the thinking state
state = state_Thinking;
break;
case state_Analyzing:
analyze();
break;
default:
System::yield();
break;
}
// Handle input
while( System::isInputAvailable() ) {
int r = handleInput();
if( r != 0 ) {
done = true;
break;
}
}
}
The isInputAvailable() method is actually only a boolean variable that is also
polled during the search. If I'm not searching, then I release the rest of the
timeslice with yield() and then check for input: this is the part where I wait.
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.