Reputation: 2774
In my program I made an obvious typo
for(int i = 0; i<mNoOfCores; i+3)
instead of
for(int i = 0; i<mNoOfCores; i++)
Unfortunately, in the loop I was generating QT5 windows. So my Ubuntu system was absolutely denied, I could only restart after power-on reset. (the mouse was responsive, and probably so was the keyboard, too.) Is there a better method? Or, in this way I can deny my OS from an application?
Upvotes: 0
Views: 77
Reputation: 962
There is no way for compiler to inform you in advance about infinite loops. This is discussed at many places, here, here, here.
What you can do is use simple "double checks" to prevent yourself from hanging the OS. Example:
int totalNoWindowsCreated = 0; // keep track of windows created OK
for(int i = 0; i<mNoOfCores; i+3)
{
// Create window
totalNoWindowsCreated++; // If created OK
assert(("Bug !", totalNoWindowsCreated <= mNoOfCores)); // Check
}
UPDATE: Of course, you can make mistake in assert condition, in that case, just take a break and drink coffee :).
Upvotes: 1