Non-Deadlock Bugs
Explore common non-deadlock concurrency bugs such as atomicity violations and order violations. Understand how these bugs arise in multithreaded programs, see examples like NULL pointer dereferences, and learn practical fixes using locks and condition variables to prevent crashes and ensure proper ordering.
We'll cover the following...
Non-deadlock bugs make up a majority of concurrency bugs, according to
- Atomicity violation bugs.
- Order violation bugs.
Atomicity-violation bugs
The first type of problem encountered is referred to as an atomicity violation. Here is a simple example, found in MySQL. Before reading the explanation, try figuring out what the bug is. Do it!
In the example, two different threads access the field proc_info in the structure thd. The first thread checks if the value is non-NULL and then prints its value; the second thread sets it to NULL. Clearly, if the first thread performs the check but then is interrupted before the call to fputs ...