Here's a sneak preview of the upcoming Typemock Racer product, which I'm currently working on. We should be out in private CTP in a couple of weeks I hope.
Typemock Racer tries to solve one huge problem for developers working in multi threaded environments: Detecting code that can result in deadlocks or race conditions. It does this by providing a framework API which you can use in your tests (under NUnit for example), that allows you to execrise your code under test until it finds a deadlock or times out.
Here's an example of how you'd use it. Consider the following class which has two methods, that if run by two seperate threads, can result in a deadlock condition:
At some point in time the threads could execute such that thread 1 is waiting on resource b, which is held by thread two , which is waiting on resource a, held by thread 1 - a pure deadlock.
Given this class we can write a test that looks like this:
The ThreadTest class has an "AddThreadAction" method that receives a delegate. you can use it to invoke your own code, it will be invoked in a different thread. IN this example we are creating two threads, each one running a different method on MyClassWithLocks.
We can just right click and run the test with TestDriven.NET to recieve the following results:
The output states that there is a deadlock that was found, with the exact steps that happened (with line locations) to reproduce this.
It currently only works with lock (monitor.Enter\Exit) but will support all locking constructs in .NET.
What if the methods you point to create their own threads? Like this:
Here is the output that you'd get if you run this test: