Formalizing and Checking Thread Refinement for Data-Race-Free Execution Models

Daniel Poetzl, Daniel Kroening

TL;DR

This paper introduces a novel, state-based theory for verifying thread refinement in concurrent programs, focusing on data-race-free execution models. By analyzing thread states at synchronization points (locks/unlocks) rather than just event sequences, their approach is more precise, allowing for more optimizations, and significantly more efficient for checking refinement, as demonstrated by a compiler testing application achieving over 200x speedup.

What Problem Does This Paper Address?

The core challenge addressed is ensuring that an optimized version of a concurrent thread remains a "refinement" of the original thread. Informally, this means that if the original thread and its context behave correctly (i.e., without data races), the optimized thread and the same context should also behave correctly and produce a subset of the original thread's possible outcomes. Traditional approaches to proving this refinement rely on analyzing sequences of events (traces) or syntactic transformations, which can be overly restrictive, preventing valid optimizations, and computationally expensive. This paper tackles the limitations of these event-based approaches by proposing a more precise and efficient state-based method.

Methods

The paper's key innovation is a state-based refinement theory. Instead of tracking every individual memory access and synchronization event, it focuses on the state of shared memory variables at the points of synchronization (specifically, lock and unlock operations).

Here's a breakdown of their approach:

  • State Traces: Threads are characterized by "state traces," which are sequences of states observed at lock and unlock operations, along with the memory locations read and written between these operations.
  • Matching Predicate: A novel match(t', t) predicate is defined. Two state traces, one from the original thread (t) and one from the transformed thread (t'), match if:
  • They have the same sequence of lock/unlock operations.
  • Their states at lock/unlock operations are consistent.
  • The set of memory locations accessed by t' between synchronization points is a subset of those accessed by t. This is crucial for ensuring t' doesn't introduce new data races.
  • Check Predicate: A check(T', T) predicate is introduced, which verifies refinement by ensuring that for every state trace of T', there exists a matching state trace of T. This predicate is designed to be more amenable to automated checking than the formal definition of refinement.
  • Handling Nested Locks: The formalization is extended to handle nested lock acquisitions, adapting the state trace and matching definitions accordingly.

Datasets

Not discussed in the paper. The evaluation uses randomly generated C threads.

Key Insights and Ideas

  • State at Synchronization is Key: The most significant insight is that focusing on thread states at synchronization points (locks/unlocks) is sufficient for proving refinement, rather than needing to track every single memory access. This simplifies reasoning and enables more optimizations.
  • Subset of Accesses for Race Prevention: The requirement that memory accesses in the transformed thread (t') must be a subset of those in the original thread (t) between synchronization points is a clever way to ensure that t' doesn't introduce new data races that weren't possible in t.
  • Enabling More Optimizations: The state-based approach allows for optimizations that event-based theories might miss, such as reordering memory accesses out of critical sections (inverse roach motel reorderings) and certain reorderings into critical sections (roach motel reorderings).
  • Efficiency Gains: By abstracting away from fine-grained event sequences and focusing on states at synchronization points, the refinement checking process becomes significantly more efficient, leading to substantial performance improvements in practical applications like compiler testing.

Key Results

  • More Precise Refinement: The state-based theory is shown to be more precise than existing event-based theories, allowing for the validation of optimizations that were previously unsupported.
  • Significant Performance Improvements: In a compiler testing scenario involving checking thread execution traces, their tracecheck tool achieved an average speedup of 210X compared to a previous event-based approach (cmmtest-check).
  • Linear Time Complexity: The proposed tracecheck algorithm has a runtime linear in the length of the traces, making it highly scalable.
  • Insensitivity to Lock Count: Unlike previous methods, their approach is largely insensitive to the number of lock operations in a trace, further contributing to its efficiency.

Limitations and Future Work

  • SC-for-DRF Model: The theory is developed for the SC-for-DRF (Sequentially Consistent with Data-Race-Free) execution model, which assumes that programs with data races have undefined semantics. Extending it to models that define semantics for data races (e.g., C++11 memory model) would be a natural next step.
  • Randomly Generated Threads: The evaluation uses randomly generated C threads. While effective for testing, real-world concurrent programs might exhibit different patterns that could influence performance or the applicability of certain optimizations.
  • Future Work: The authors suggest adapting the formalization to other memory models and exploring its application to more complex optimization scenarios.

Summary updated

Abstract

When optimizing a thread in a concurrent program (either done manually or by the compiler), it must be guaranteed that the resulting thread is a refinement of the original thread. Most definitions of refinement are formulated in terms of valid syntactic transformations on the program code, or in terms of valid transformations on thread execution traces. We present a new theory formulated instead in terms of state transitions between synchronization operations. Our new method shows refinement in more cases and leads to more efficient and simpler procedures for refinement checking. We develop the theory for the SC-for-DRF execution model (using locks for synchronization), and show that its application in compiler testing yields speedups of on average more than two orders of magnitude compared to a previous approach.
BibTeX
@inproceedings{poetzl2016formalizing,
  author = {Daniel Poetzl and Daniel Kroening},
  title = {{Formalizing and Checking Thread Refinement for Data-Race-Free Execution Models}},
  booktitle = {TACAS},
  year = {2016},
  doi = {10.1007/978-3-662-49674-9\_30},
}
Figure