<an*****@yahoo.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi guys,
is there any utility available as a protection against endless_loop()
something like this:
alarm.set(5); //set timeout for 5 sec
endless_loop();
alarm.reset(); //reset it to 0, as alarm not needed any more
Thanks,
Perhaps there exists such a utility, but as it
would not be standard C++, it would not be topical
here. However, a simple way to implement this would
involve instrumenting the loop itself. Before
the loop begins, capture a time with std::clock(),
and at one or more points inside the loop, capture
the time again. The difference between it and the
one obtained outside the loop would give elapsed time.
Compare it with your desired 'time-out' value. Break
the loop if elapsed time >= your time-out value.
See standard library documentation for details on
how to use 'std::clock()'.
-Mike