[Issue 14419] [CTFE] Need infinite loop detection?
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Apr 7 09:31:20 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14419
--- Comment #16 from Jens Bauer <jens-bugzilla at gpio.dk> ---
(In reply to Iain Buclaw from comment #15)
> So then you just need to decide what is a suitable iteration limit,
> short.max? ushort.max?
If it's just to make sure that "we're not stuck forever", the size of the
returned argument might be suitable.
I believe this is very much a matter of opinion, though.
But consider this. Combining with my previous idea of checking the
exit-conditions.
All sources for the exit-conditions should be saved (the stack would be fine):
All minimum values for the exit conditions
All maximum values for the exit conditions
A minimumHit counter
A maximumHit counter
Each time the same minimum for all exit conditions are hit, then the minimumHit
counter is incremented.
If a new minimum is found, the minimumHit counter is cleared.
Same thing for the maximumHit counter.
Now if any of those two counters reach a value above - say 10, then we'll exit
the loop.
As a fail-safe, an unsigned 32-bit counter could be used as an 'absolutely
maximum limit'.
This is just an idea, but I believe it would be fairly good at catching more
than 99% of the lockups.
--
More information about the Digitalmars-d-bugs
mailing list