Search⌘ K

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.

Non-deadlock bugs make up a majority of concurrency bugs, according to Lu’s study“Learning from Mistakes — A Comprehensive Study on Real World Concurrency Bug Characteristics” by Shan Lu, Soyeon Park, Eunsoo Seo, Yuanyuan Zhou. ASPLOS ’08, March 2008, Seattle, Washington. The first in-depth study of concurrency bugs in real software, and the basis for this chapter. Look at Y.Y. Zhou’s or Shan Lu’s web pages for many more interesting papers on bugs.. But what types of bugs are these? How do they arise? How can we fix them? We now discuss the two major types of non-deadlock bugs found by Lu et al.:

  • 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!

C
Thread 1::
if (thd->proc_info) {
fputs(thd->proc_info, ...);
}
Thread 2::
thd->proc_info = NULL;

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 ...