# include <io.h>\r
HANDLE process;\r
DWORD thread_id;\r
+ void Bury(int s) { if(WaitForSingleObject(process, 1000*s+50) != WAIT_OBJECT_0) TerminateProcess(process, 0); }\r
#else\r
# include <pthread.h>\r
# include <signal.h>\r
# include <unistd.h>\r
# define NO_ERROR 0\r
# include <sys/time.h>\r
+# include <sys/wait.h>\r
int GetTickCount() // with thanks to Tord\r
{ struct timeval t; gettimeofday(&t, NULL); return t.tv_sec*1000 + t.tv_usec/1000; }\r
//# include <unistd.h>\r
int Sleep(int msec) { return usleep(1000*msec); }\r
+ int pid; void Bury(int msec) { Sleep(msec+50); if(waitpid(-1, NULL, WNOHANG) <= 0) kill(pid, SIGKILL); }\r
#endif\r
#include <fcntl.h>\r
#include <string.h>\r
char currMove[20], moveMap[500][10], /* for analyze mode */ canPonder[20], threadOpt[20], varList[8000], anaOpt[20], checkOptions[8192] = "Ponder";\r
char pvs[99][999], board[100]; // XQ board for UCCI\r
char *nameWord = "name ", *valueWord = "value ", *wTime = "w", *bTime = "b", *wInc = "winc", *bInc = "binc", newGame; // keywords that differ in UCCI\r
-int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways, newCnt, priority;\r
+int unit = 1, drawOffer, scores[99], mpvSP, maxDepth, ponderAlways, newCnt, priority, killDelay;\r
\r
FILE *toE, *fromE, *fromF;\r
-int pid;\r
\r
char *strcasestr (char *p, char *q) { while(*p) { char *r=p++, *s=q; while(tolower(*r++) == tolower(*s) && *s) s++; if(!*s) return p-1; } return NULL; }\r
\r
p = line; while(qEnd < queue+10000 && (*qEnd++ = *p++) != '\n') {}\r
Sync(WAKEUP);\r
// when 'stop' doesn't catch engine's attention in reasonable time, so the GUI might kill us:\r
- if(!strcmp(command, "quit")) { Sleep(500); EPRINT((f, "quit\n")); } // make sure 'quit' is still sent\r
+ if(!strcmp(command, "quit")) { Bury(killDelay); exit(0); } // kill the engine and exit\r
}\r
}\r
}\r
if(sc == 's') EPRINT((f, "# gameover %s\n", line[8] == '/' ? "draw" : (line[7] == '0') == mySide ? "win" : "lose"))\r
computer = NONE;\r
}\r
- else if(!strcmp(command, "quit")) { EPRINT((f, "# quit\n")) fflush(toE), exit(atoi(line+4)); }\r
+ else if(!strcmp(command, "quit")) { EPRINT((f, "# quit\n")) fflush(toE); }\r
else printf("Error (unknown command): %s\n", command);\r
\r
fflush(stdout);\r
CloseHandle(hChildStdoutWr);\r
\r
process = piProcInfo.hProcess;\r
- pid = piProcInfo.dwProcessId;\r
fromE = (FILE*) _fdopen( _open_osfhandle((long)hChildStdoutRd, _O_TEXT|_O_RDONLY), "r");\r
toE = (FILE*) _fdopen( _open_osfhandle((long)hChildStdinWr, _O_WRONLY), "w");\r
#else\r