Chapter 11. Testing and debugging multithreaded applications
This chapter covers
- Concurrency-related bugs
- Locating bugs through testing and code review
- Designing multithreaded tests
- Testing the performance of multithreaded code
Up to now, I’ve focused on what’s involved in writing concurrent code—the tools that are available, how to use them, and the overall design and structure of the code. But there’s a crucial part of software development that I haven’t addressed yet: testing and debugging. If you’re reading this chapter hoping for an easy way to test concurrent code, you’re going to be sorely disappointed. Testing and debugging concurrent code is hard. What I am going to give you are some techniques that will make things easier, alongside some issues that are important to think about.
Testing and debugging are like two sides of a coin—you subject your code to tests in order to find any bugs that might be there, and you debug it to remove those bugs. With any luck, you only have to remove the bugs found by your own tests rather than bugs found by the end users of your application. Before we look at either testing or debugging, it’s important to understand the problems that might arise, so let’s look at those.