I am writing a chess game that allows you to compete with two programs, the player needs to write a DLL and set up a function to tell the main application where his player will move on, suppose the function looks like this:
public static void MoveNext(out int x, out int y, out int discKind);
Player DLLs can be written using C # or C ++.
In a chess game application, I start a new thread to call the function that the DLL player found in order to get a place where it will move in a turn, and I start a timer to prevent the player timeouts if the game timeout I kill the corresponding stream following API
thread.Abort(); thread.Join();
I have the following problems as described below:
A thread cannot be killed with 100% certainty (it depends on the player’s code)
During the test, I found that if the player uses deep recursions (and if there is a memory leak in the player program), the memory usage of the host application will increase, and then the host application will be terminated without any exception.
Are there any methods, ideas, or methods that can handle the above problems?
From this, CodeInChaos suggests loading the player’s DLL into a separate domain and then unloading it when necessary, I'm not sure if it still works for an unmanaged DLL (C ++), and if this leads to low efficiency?
Carlos Liu
source share