I basically need a function that, after a certain amount of time has elapsed, will restart a program from scratch. This is because the code can get stuck at a certain point if wrong decisions are made. I am curious how to go about making this. I am sure it should be quite simple. Could I just use some sort of time function for this? For example, when time = 30 seconds since last restart, the program starts over?

9 Years
Discussion Span
Last Post by Ancient Dragon

By stuck I suppose you mean the program goes into an infinite loop or possibly even crashes. You should fix the problem instead of attempting to hide it.

Votes + Comments
Good advice

It could just hang waiting for some input which it's not getting, in that case we need to check the time elapsed and restart the program. Frankly speaking i cant think of a way to do it rt away, and i'm in a little hurry, but this was just to get AncientDragon thinking in this direction


Oh, you mean keyboard input. In that case you need to create another thread. The main thread should do the timing and the second thread the keyboard input. When time expires in the main thread, main() kills the keyboard thread then does other things.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.