Abstract
Many parallel programming models guarantee that if all sequentially consistent (SC) executions of a program are free of data races, then all executions of the program will appear to be sequentially consistent. This greatly simplifies reasoning about the program, but leaves open the question of how to verify that all SC executions are race-free. In this paper, we show that with a few simple modifications, model checking can be an effective tool for verifying race-freedom. We explore this technique on a suite of C programs parallelized with OpenMP.
Introduction
Writing multithreaded code is notoriously difficult due to the non-intuitive ways modern hardware and compilers reorder operations. To manage this complexity, most programming languages offer a contract known as the "Sequential Consistency for Data-Race-Free" (SC4DRF) guarantee. This contract states that if a programmer ensures their program is free of data races—defined as two threads accessing the same memory location simultaneously where at least one access is a write—the system will guarantee Sequential Consistency (SC). Under SC, the program behaves as if threads simply take turns executing one step at a time.
While SC4DRF simplifies the mental model for developers, it places the burden of proof on the programmer to ensure the program is indeed race-free. This paper addresses the challenge of verifying race-freedom in C/OpenMP programs using a specialized model-checking approach.
The Verification Challenge
Existing tools for detecting data races generally fall into two categories, each with significant drawbacks:
- Dynamic Analyzers: These tools are precise but limited to the specific execution paths triggered during a run. They often miss races that occur only under rare thread interleavings.
- Static Analyzers: These can check all possible paths but are often imprecise. They frequently report "false alarms" because they struggle to accurately model complex pointer logic or synchronization primitives.
Model checking offers a potential solution by exhaustively exploring all possible interleavings. However, it traditionally suffers from "state explosion," where the number of states to check grows exponentially with the number of threads and operations.
Methodology: Optimizing CIVL for Race Detection
The authors implement their approach within the CIVL (Concurrency Intermediate Verification Language) framework. To overcome the state explosion problem, they introduce two key modifications to standard reachability algorithms:
1. Access History Tracking
Instead of performing expensive race checks at every memory access, each thread maintains a local "history" of the memory locations it has read or written since its last synchronization point (e.g., a lock or barrier). The tool only checks for conflicts when a thread reaches a new synchronization point or terminates. This significantly reduces the computational overhead of monitoring memory.
2. Aggressive Partial Order Reduction (POR)
Partial Order Reduction is a standard technique used to avoid exploring redundant interleavings. Typically, any access to a shared variable is considered "non-local," requiring the model checker to explore different execution orders.
The authors' "Aha!" moment was realizing that the property they are trying to prove—race-freedom—allows for a much more aggressive reduction. By assuming the program might be race-free, they can treat shared memory accesses as "local" for the purpose of reduction. Only explicit synchronization operations are treated as non-local. If a race exists, this reduced search is still mathematically guaranteed to find it; if the search completes without finding a race, the program is proven race-free within those bounds.
Experimental Evaluation
The researchers evaluated their tool using two primary datasets:
- DataRaceBench (DRB) v1.3.2: A standard benchmark suite for OpenMP race detection. The study focused on a subset of 88 benchmarks compatible with the tool's current feature set.
- Custom Benchmarks: Ten additional programs designed to test complex concurrency patterns, such as busy-wait loops, 1D-diffusion simulations, and producer-consumer patterns.
Key Results
The tool was compared against LLOV, a state-of-the-art static analyzer.
- Precision: CIVL correctly identified 40 out of 41 race-free programs and 45 out of 47 racy programs in the DRB subset.
- Accuracy in Complexity: While LLOV was faster, it produced several false positives on the custom benchmarks. CIVL handled indirect addressing and unstructured synchronization (like busy-wait loops) correctly, where other tools failed.
- Small Scope Hypothesis: The results support the idea that most concurrency bugs manifest in small configurations (e.g., 2-3 threads). By verifying these small instances exhaustively, developers can gain high confidence in the program's overall correctness.
Conclusion and Future Work
This research demonstrates that model checking can be a sound and precise tool for verifying race-freedom by leveraging the SC4DRF guarantee to prune the search space. While the current prototype does not yet support the full OpenMP specification (missing features like task or target directives) and requires some manual instrumentation, it provides a robust framework for eliminating the "false alarms" common in static analysis.
Future work will focus on expanding OpenMP feature coverage and improving the efficiency of the tool when handling nondeterministic choices in worksharing constructs.
Summary updated