Author: Robert Hyatt
Date: 16:58:38 08/29/04
Go up one level in this thread
On August 29, 2004 at 12:04:47, Uri Blass wrote: >I have the following code similiar to tscp (tscp is using the variable line >instead of buffer. > >if (!fgets(buffer, 256, stdin)) > return; > >I have the following questions: >1)How is it possible to have >!fgets(buffer, 256, stdin) > >I understand that it happens only in case of an error but >I do not see how there can be an error. \ Easy. I run my code, do a pipe() call to create a pipe, then do a fork() to create a new process. In that new process, I do a dup2() to make stdin read from the pipe, and then I exec() your program. Every time your program tries to read stdin, it reads the pipe I created which means it reads what I write into the pipe. What happens if my program crashes? You are left with stdin connected to a pipe that has nobody on the other end, so no read can ever be satisfied. This is to handle that case. That is how xboard/winboard does its "thing" in fact... > >2)Is it safe to use fgets()? >I remember that it is not safe to use gets() and I think that for the same >reason it is not safe to use fgets() No, because it is buffered, and testing to see if you have something to read works strangely when there is a library buffering issue in between your program and the operating system. > >3)I plan to replace this code by a waiting function. >The point is that I need to wait passively to commands in different places >one case is when I do not ponder and it is the opponent move but even when I >ponder during the search I may want to wait(for example if I finished the >maximal depth). > >Today movei has no waiting function and in case of finishing to search during >pondering it simply unmake the pondered move and go to the main loop. > >I think that it is better not to finish the search in case of pondering and >simply call wait during the search to wait passively to winboard command when >wait may call a function that read wb input during searching(can be ponder mode >play mode or analysis mode). > >Do you have a waiting function in your code? > >Uri That sounds like a clumsy way of doing this. Just have a global variable "ponder_done" or something, so that you can tell whether you are in the main loop with nothing to do because a ponder search terminated with a forced mate, or whether you are simply not pondering at all...
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.