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:
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:
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
An "engine" that permanently does calculations (while (++nodecount)) is probably easy to kill. But what if that "engine" itself is hanging while waiting for an event (e.g. input) that does not come? Or one that performs a huge amount of disk I/O? Or one that allocates lots of resources (e.g. memory) which need to be freed?
Sven Schüle wrote:An "engine" that permanently does calculations (while (++nodecount)) is probably easy to kill. But what if that "engine" itself is hanging while waiting for an event (e.g. input) that does not come? Or one that performs a huge amount of disk I/O? Or one that allocates lots of resources (e.g. memory) which need to be freed?
In fact I expect that this kind of engine can give some problem. The test that I've done is related to Satana, that use separate threads for console I/O, for the search and for the main loop that handle commands.
The memory allocated by a process I hope that would be released if you kill the process (not very sure for this and maybe it is OS related). Not the same for other resources, for sample GDI resources on Windows and other system resources. Of course we talk about chess engines and we can expect that they would open sygyzy files, ini files, pgn files and so on; I don't expect that a standard engine can needs windows and other graphical resources... ops... my old program Raffaela just do it!
And what about a software that spoke the moves with a sexy voice? It could lock the audio API forever (even if the voice isn't sexy, of course).
PS: tested on Raffaela and it works; almost the memory seems to be released correctly but maybe I should run it some thousands times, to notice some lost resource
Sven Schüle wrote:The memory, or other resources, may be released correctly but my point was that this may delay process termination in some cases.
Yes, maybe a variable timeout parameter is needed, for some engine, to terminate the process as later as possible, without hanging too long the interface itself.