Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-11

Any Way to catch endless loop in fpc in Wince?

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe
to epergola: Hi Is there a way (or a 3rd party component or a library) to catch an endless loop after…
epergola wrote
Is there a way (or a 3rd party component or a library) to catch an endless loop after x seconds in applications running on arm Wince?

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

If you have multiple threads in your program, you will need multiple global variables.

Jonas

JoshyFun
to Jonas Maebe

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