views:

306

answers:

4

Is there a tool that analyses .NET code and finds race conditions?

I have a bit of code that has a public static property that gets or creates a private static field. It also has a public static method that sets this field to null (...yes, I know!..)

As there are no locks around either of these methods, it's a safe bet that things'll go horribly wrong in the future. I need a tool that'll recursively go through things that call either of these methods and see if anything was spawned on another thread.

I'm looking for a tool or perhaps an nDepend SQL script (if this is possible).

+2  A: 

You might want to check out CHESS.

HTH,
Kent

Kent Boogaart
+7  A: 

You're probably looking for one of these:

Lasse V. Karlsen
Thanks Lasse,I'd heard of CHESS but not TypeMock Racer.I was really looking for a tool that did static analysis of the code. I'm using ReSharper 5 which has a nice feature that inspects code and shows all callers of a particular method and drills down through them recursively. What I need is something that'd flag a method as being instantiated on a worker thread. I'll investiage more on the CQL approach, as I know there's an upstream callers script, so I'm sure there's a way of finding out if any methods are the result of a thread invocation call.
Steve Dunn
+1  A: 

Jinx will do this at runtime (not statically) but it may be worth looking at.

John Gietzen
Nice. Runtime analysis is far superior to static analysis of concurrency issues. There's just too much runtime convention for the static analyzers to produce a good signal-to-noise ratio.
Michael Donohue
A: 

Have you looked at Red-Gate Ants? I'm not sure if it will do everything you need but it is a good product to:

  • Identify performance bottlenecks within minutes
  • Optimize .NET application performance
  • Drill down to slow lines of code with line-level timings
  • Profile aspx, ASP.NET, C# code, and VB.NET applications
Keith Barrows