Author: Peter McKenzie
Date: 21:13:31 02/22/01
Go up one level in this thread
On February 22, 2001 at 21:06:42, Scott Gasch wrote:
>
>>I think spinning off a thread is the best answer. I expected the standard C
>>functions for this would work OK on Unix, however. PeekNamedPipe, etc. has
>>always seemed to be quirky in my experience. Besides, it doesn't port to Unix
>>either, right? In any case, by my experience, kicking off a thread is easiest
>>and gives the best performance in Windows.
>
>Those of you who say to kick off a thread for win32... how does one do in such a
>way so that CSRSS.EXE doesn't consume massive CPU?
what is CSRSS.EXE by the way?
>
>CreateThread then GetStdHandle then WaitForSingleObject on the handle in a loop?
> When the wait call wakes up flag a global identifier for the engine and wait
>for the engine to clear the flag?
>
>Is it better to just do my own I/O... when the wait call returns read into a
>private buffer, set a flag, flush stdin and have to engine draw command out of
>my own private buffer so that the wait flag can go back to waiting immediately
>and not spin?
I don't use WaitForSingleObject. I hacked my own system, probably not optimal
from a software re-use perspective but it was fun :-) My reader thread does
something like the following:
for (;;) {
if (BufferFull()) {
Sleep(0);
}
else {
char str[100];
cin >> str; // this blocks if there is nothing to read
AddToBuffer(str);
}
}
So my buffer is a global, and there are also global indexes into the buffer for
the next read and the next write. There are possible race conditions when
comparing those two indexes, I solve those with some flags but I guess you could
use some kind of mutex too.
>
>Has anyone done this already? This might be something Bob would be interested
>in too as I see the crafty code causes the CSRSS.EXE problem too...
>
>A related question: why does WaitForSingleObject on a stdin handle return when
>no key has been pressed... can I somehow ignore mouse and resize events?!
>
>Thanks for the help, everyone.
>Scott
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.