[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Detect infinite loops via software

Posted on 2007-11-27
8
Medium Priority
?
1,043 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 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