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

Jonas Maebe jonas.maebe at elis.ugent.be
Wed Nov 11 10:34:09 CET 2009


On 11 Nov 2009, at 00:55, 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



More information about the fpc-pascal mailing list