views:

406

answers:

5

I have an application written in C++ and MFC which is multithreaded running on windows. Occasionally I do get some complaints such as deadlocks or an unhandled exception which is caused because of these threads. Normally I use visual studio (if the problem is reproducible) or else use the WinDbg to analyse the dump files generated. Is there any better way of doing this? Can I use some other tools to do this?

+1  A: 

Multithreaded system are complex and location of blockages is not made only with appropriate tools. To find the cause of the deadlock you can put a record of the lock / unlock in a table map. When starting an "action lock" you save in the table, when unlock ocours delete the record from the table. At the end of a cycle you can log the state of the table or expect a particular event to do this.
Build this implementation in a dll, so you can use it in other projects too.

lsalamon
+3  A: 

I would recommend the Intel Thread Checker if you have enough budget for it. It does a great job of analysing running programs and alerting you to possible race conditions.

Check out the demonstration video for more info.

Casey
+2  A: 

I haven't gotten to use it yet, but the Relacy Race Detector sounds pretty useful for tracking down some classes of threading issues.

Dan Olson
+2  A: 

If you're deadlocking on CRITICAL_SECTIONs, you can use the !locks debugger extension in WinDbg to find out which thread owns a held lock, then use the kb command to look at that thread's callstack.

George V. Reilly