I have a console Windows application written in C++ that finds a solution (or proves non-existance of solution) for a given level for some step-by-step game. Let's call it "solver". This application is launched in a loop from Python script for all game levels. Some levels are too difiicult and it takes hours ot even days to solve them.
It would be acceptable if my application could output some string, say "Too difficult level" and exit thus allowing to Python script to move onto the next level, if it has failed to find a solution (or to prove its inexistance) in, say, 30 minutes.
How do I interrupt the solver 30 seconds after it has started? Technically, solving algorithm is just a recursive procedure called from int main()
.
I am thinking over creating secondary thread that would wake up 30 minutes after being launched and set some boolean flag. And primiry (solving) thread would check this flag periodically.
This would work, but isn't there any simpler of more elegant solution?