Moderator: Andres Valverde
Naum wrote:Hi Uri,
I intended this to be just for fun. At least to me, this was an interesting information.
It doesn't matter what you do during the search. I am talking about input polling that engine is doing after it plays the move and starts waiting for Winboard to send the opponents move (ponder is off).
Regards,
Alex
Naum wrote:While looking at Alessandro's very nicely written engine input library, I noticed that he uses something like:
while (!isInputAvailable())
Sleep(1);
I didn't like this solution and decided to test how much of opponents time you 'steal' if you use this technique instead of the Microsoft recommended WaitForSingleObject().
Naum wrote:I am still not sure, but it seems that PeekNamedPipe can't be reliably used to check if there is something waiting in the input buffer used by fgets.
In order for your fgets() to work properly you are probably disabling the buffering (by calling setbuf and setvbuf).
I think that using the Win APIs only is safer then mixing the WinAPI and c runtime library functions.
You could replace the fgets() with something like:
WaitForSingleObject(hInput, INFINITE); // Waits until there is input available
ReadFile(hInput, buffer, length, &numRead);
hInput is the handle to stdin you use in your PeekNamedPipe call.
The only difference is that ReadFile works in the same way as _read() and not like fgets(), so you would have to do more coding to handle the new-line characters.
All this stuff is already implemented in Alessandro's free source.
Alex
Naum wrote:While looking at Alessandro's very nicely written engine input library, I noticed that he uses something like:
while (!isInputAvailable())
Sleep(1);
I didn't like this solution and decided to test how much of opponents time you 'steal' if you use this technique instead of the Microsoft recommended WaitForSingleObject()
Result on my AMD3000 with WinXP was 0.1%
I am guessing that on a slower hardware and with the OS that doesn't have a proper implementation of multi-threading and process switching (Win98, etc.) the percentage might be bigger.
It is a small difference, but still it would be nice if people would avoid using Sleep() technique if possible.
Regards,
Alex
Jos? Carlos wrote:I use scanf() to sit waiting for input. Is there any negative effect that I'm missing?
Alessandro Scotti wrote:Jos? Carlos wrote:I use scanf() to sit waiting for input. Is there any negative effect that I'm missing?
Yes, you will be losing about 0.08 elo when matched against Kiwi with ponder off, so watch out!
do
{
getline(cin, strInput);
// do something with the input
} while (We don't need to leave);
mathmoi wrote:From what you say I understand that there is an overhead when using a blocking read instruction. Can you explain why?
Alessandro Scotti wrote:mathmoi wrote:From what you say I understand that there is an overhead when using a blocking read instruction. Can you explain why?
Hi Mathieu,
quite the contrary in fact! Blocking consumes no CPU, while polling takes a little amount of CPU time.
Daniel Shawul wrote:I use Sleep(100) , I am not as "bad" as Alessandro
Seriously though, how are multi threaded engines supposed to
park the threads when it is not their turn? I am sure WaitForSingleObject() does something similar. Killing and creating does not seem a good solution.
Daniel
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 23 guests