Author: Steven Edwards
Date: 09:38:17 09/10/03
Some programs like Crafty currently use a node count check to determine if a
time check or interface check is needed. The code in Crafty looks like:
tree->nodes_searched++;
if (--next_time_check <= 0) {
next_time_check=nodes_between_time_checks;
if (tree->thread_id==0 && CheckInput()) Interrupt(ply);
if (TimeCheck(tree,0)) {
time_abort++;
abort_search=1;
return(0);
}
Now, the above works, but its behavior is dependent on the node search rate, and
this is going to be different from machine to machine. The code may do time
checks more often than needed (a loss of efficiency) or it may do too few (a
loss of responsiveness).
A better approach is to use a separate thread to wait efficiently for a constant
time interval.
At the start of the search, the program starts a separate thread and passes it a
pointer to a timeout variable and a pointer to an exit flag. The timeout
variable is just an integer which has a zero value (meaning that the timer
interval has not expired) or a nonzero value (the interval has expired). The
exit flag pointer is used to tell the thread when to exit. The thread code for
a 1/10th second interval looks like:
void Time100ms(int *theTimeOutPtr, int *theExitFlagPtr)
{
*theTimeOutPtr = 0; *theExitFlagPtr = 0;
while (!*theExitFlagPtr)
{
usleep(100 * 1000);
*theTimeOutPtr = 1;
};
}
At each search node, the code looks like
if (*theTimeOutPtr)
{
*theTimeOutPtr = 0;
/* do various time check related processing */
};
At the conclusion of the search, the code does
*theExitFlagPtr = 1;
followed by thread clean up with pthread_join() or whatever.
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.