I'm writing a new chess engine graphical interface, that create separated processes to control external engines, redirecting console I/O. At present it seems to works but I'm not sure about the way that I exit from the interface. I don't want that the interface hangs if an external process is somehow bugged, so I drastically terminate that processes this way:
Code: Select all
clsWxBoard::~clsWxBoard()
{
if(pTimer)
{
pTimer->Stop();
SmartDelete(pTimer);
}
for (int i = 0; i < cllEngines.Count(); i++)
{
cllEngines[i]->Push("quit");
cllEngines[i]->Terminate(1000);
cllEngines[i]->Join();
}
cllEngines.Clear();
objSatana.PushCommand("quit");
objSatana.Join();
delete bmpBoard;
delete bmpSprites;
return;
}
clsWxBoard is derived from a wxWidgets component, so that I could port the code on Windows/Mac/Linux (actually only the Windows version works). What I'm asking is if it is ok to presume that in one second the external process has quit cleanly; my Terminate function does this:
Code: Select all
bool clsRedirectedChild::Terminate(int wait_ms)
{
Sleep_ms(wait_ms);
return TerminateProcess(pi.hProcess, 0)==TRUE;
}
Waiting for the process to terminates after the quit command sent maybe could lock my interface (that would not be good) but terminating a process with TerminateProcess could cause some corruption in its ini files or something similar.
Maybe I could try with some bugged engine, just to see what happens in any condition... if someone could suggest one