How to test for thread safety [duplicate] How to test for thread safety [duplicate] multithreading multithreading

How to test for thread safety [duplicate]


You can use some good tools to test all the threading issues like Data races, deadlocks, stalled threads etc.intel-thread-checker is one such good tool.

You can also try, CHESS by Microsoft Research


Try increasing the number of threads to a large number if possible, even beyond how many will be used in a release. With lots of threads running your program, an error will appear more often since more threads are running over the code.

Double check your declarations, locks, unlocks, semaphore counts, etc and make sure they make sense.

Create a test document or spreadsheet, and using your knowledge of the code, think about where possible race conditions or deadlocks could occur.

Grab some people from the hall and do a 'hallway usability test' (Joel on Software said that I think?). Generally, people who have no idea what your program does/is about will be able to break it easily.


Good question. I usually test for race-conditions by spawning many threads and letting them wildly perform the operations which I suspect might be subject to race conditions.

Maybe you can look at PNUnit - although it's probably a little different from what you are looking for. The authors say they built it because "we needed to simulate hundreds of clients against the same server".