[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Detect infinite loops via software

Posted on 2007-11-27
8
Medium Priority
?
1,034 Views
Last Modified: 2008-03-29
Is there any software product that can detect potential infinite loops in  your code? In other words, something like an editor that I can open up (I use .NET) a .cs file and it would, say, underline any code (or something like that) that could potentially cause infinite loops?
0
Comment
Question by:jeremyduj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20361382
there are hundreds of situations where you cannot detect infinite loop until program is running and some variables are set. This is a lazzy and inaccurate approach, better you focus in becoming a good programmer.
0
 
LVL 1

Author Comment

by:jeremyduj
ID: 20361498
that was a pretty useless comment.
0
 
LVL 22

Expert Comment

by:JimBrandley
ID: 20363401
Consider the following:
while (!otherThreadComplete)
   sleep(1000);
// Now do something useful.

What happens if something blocks the other thread. This is reasonable code, but is a potential infinite loop. While it would be possible to detect a missing index incrementor in a simple loop, many loops involve variables and methods of other objects.

Because of the complexity of trying to obtain reasonable code coverage, I do not think anyone has made the attempt. I have certainly never seen one.

Jim
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Expert Comment

by:evilrix
ID: 20365272
Hmm, well I'm not sure about C# but certainly C++ has a number of tools that can be used at build time to detect and report such possibilities (such as Coverity).

That said, as useless as you think the comment by @jaime_olivares is (I don't!) he does, in fact, raise a perfectly valid point! For example, say you read in a variable from a config file and your loop exit is predicated on a specific value of that config. It is conceivable that your code will enter an infinite loop unchecked. It is possible that a tool may not spot that and, as such, it is better to code defensively against such possibilities.

The way a lot of professional software companies try to mitigate against such situations is to implement code reviews. Basically, the source code is checked into a central review repository (such as CodeStriker) and reviewed by other developers. Comments are actioned and the process repeated until all reviewers are satisfied that the code is fit for purpose.

-Rx.

0
 
LVL 1

Author Comment

by:jeremyduj
ID: 20366208
Well, I literally have about 10 running applications on the web server and I didn't write all the code for every single program, so I'm really not sure where the infinite loop is coming from. There are literally hundreds of thousands of lines of code ... just trying to find a quicker approach than to go through thousands of lines of code looking for a loop! Actually, have you guys tried looking at this program here http://www.iistools.com/en/iisguard.html - it monitors IIS and may be able to pinpoint what page of what program is causing the infinite loop... I'm going to go ahead and install this and perhaps I'll be able to find the culprit! But of course this requires that I await the next infinite loop - and everybody goes crazy at work because the applications are running too slow. I was thinking before that if I could run every .cs file through some kind of editor, that it could pick up potential infinite loops such as something extremely simple as While(1) - even though its simple to fix, you have to pinpoint that one line of code in about 100 .cs files that all have 5000 lines of code or more!  I'll keep looking. Thanks.
0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 2000 total points
ID: 20366825
Can you duplicate the problem running through the debugger? If so, you can just break and check the call stack when you are pretty sure you are in it. Another way to detect it would be to start the app in a profiler (we use Ants from Redgate). After it runs for a time and you have encountered the loop problem, a snapshot will allow you to see the code that's executing more frequently than it should.

Jim
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20367125
>> something extremely simple as While(1) - even though its simple to fix,
Not necessarily! The body of the while loop may be very complex and contain numerous break and continue clauses (not that I advocate such heinous code)!

0
 
LVL 7

Expert Comment

by:photowhiz
ID: 20367180
What you are asking for is mathematically impossible: http://en.wikipedia.org/wiki/Halting_problem
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question