[fpc-pascal] Any Way to catch endless loop in fpc in Wince?

JoshyFun joshyfun at gmail.com
Wed Nov 11 11:47:40 CET 2009


Hello FPC-Pascal,

Wednesday, November 11, 2009, 10:34:09 AM, you wrote:

JM> It is not possible to know whether a loop is endless or not (at least
JM> not in the general case, see the "halting problem"). If you simply
JM> want to know whether your application has run its main loop within the
JM> last x seconds, you can use a global variable and an extra thread:
JM> * set the variable to 1 in the thread and sleep x seconds (note that
JM> you have to do this with interlockedexchange, otherwise you can get
JM> memory synchronisation issues)
JM> * set it to 0 whenever you execute the main application loop (idem)
JM> * if it's still 1 when the thread wakes up then the main application
JM> loop has not run for x seconds
JM> If you have multiple threads in your program, you will need multiple
JM> global variables.

Or maybe using the same system as Windows, post a custom message to
the application and the handler of that message notify the watchdog
thread with an acknowledge procedure. If acknowledge takes more than
"X" seconds them the "hang" in endless loop is quite sure. Or maybe
in the "OnIdle" event of the application ?

-- 
Best regards,
 JoshyFun




More information about the fpc-pascal mailing list