Author: Steven Edwards
Date: 06:20:33 09/12/03
Go up one level in this thread
On September 10, 2003 at 12:38:17, Steven Edwards wrote:
>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;
> };
>}
Better, here's the actual instance method code from the SPCT:
void CTTimer::Run(void) const
{
volatile bool *theFlagPtr = GetFlagPtr();
unsigned int theMicroSecondPeriod = GetMicroSecondPeriod();
*theFlagPtr = false;
while (!IsDoomed(GetTRIndex()))
{
usleep(theMicroSecondPeriod);
*theFlagPtr = true;
};
}
(Note the use of the "volatile" storage qualifier.)
The value returned from GetTRIndex() is the trhead record index, a sort of file
descriptor for a thread. It is a done-once mapping of the value of
pthread_self() onto small non negtive integers that are used for indexing a
vector of thread information records.
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.