kinderchocolate wrote:
Thanks. I've seen the diffs I think your changes will work. The changes look very familiar, it was copied from Stockfish, wasn't it? I'll report to you if I have any questions.
No, this code was written by me:
* I wrote the POSIX version myself, simply looking at the documentation for the select() system call. select() is an extremely powerful function by the way. And what makes it even more powerful is that POSIX treats any kind of file descriptor the same (file on a disk, but also pipe, console, network socket, you name it...)
* The Windows version is based on Fruit as well as the documentation I could find on microsoft.com. I believe my implementation is somewhat better/simpler than the original Fruit one. The Windows case is a real mess, because the design of Windows is so flawed and stupid: Windows treats every kind of file descriptor completely differently, so there's no uniform way of doing this for all of them (console, pipe, file, etc.)
Stockfish does this in a completely different way, using threads:
The Stockfish method works as follows
* a master thread is parked in a loop that does a blocking I/O read from stdin
* once the data becomes available (if at all), the call returns and the master thread is scheduled by the operating system again. So it parses the result, and if it happens to be a "stop" then it sets a global variable Signals.Stop = true
* Then all the searching thread(s) observe that Signals.Stop variable, and when it's true, they know it's time to stop.
The Stockfish method is arguably better, because:
* it can be written only with portable code (at least in C11 or C++11)
* my implementation is potentially racy in the SMP case. But I don't care, as DiscoCheck is single threaded.
* it's also more elegant.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.