concept bug in category c++

appears as: bug, bugs, bugs, bug
C++ Concurrency in Action, Second Edition

This is an excerpt from Manning's book C++ Concurrency in Action, Second Edition.

Designing lock-free data structures is a difficult task, and it’s easy to make mistakes, but these data structures have scalability properties that are important in some situations. Hopefully, by following through the examples in this chapter and reading the guidelines, you’ll be better equipped to design your own lock-free data structure, implement one from a research paper, or find the bug in the one your former colleague wrote before they left the company.

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.

In the previous section we looked at the types of concurrency-related bugs you might see and how they might manifest in your code. With that information in mind, you can then look at your code to see where bugs might lie and how you can attempt to determine whether there are any bugs in a particular section.

Perhaps the most obvious and straightforward thing to do is look at the code. Although this might seem obvious, it’s difficult to do in a thorough way. When you read code you’ve written, it’s all too easy to read what you intended to write rather than what’s there. Likewise, when reviewing code that others have written, it’s tempting to give it a quick read-through, check it off against your local coding standards, and highlight any glaringly obvious problems. What’s needed is to spend the time going through the code with a fine-tooth comb, thinking about the concurrency issues—and the nonconcurrency issues as well. (You might as well, while you’re doing it. After all, a bug is a bug.) We’ll cover specific things to think about when reviewing code shortly.