TL;DR
This paper introduces a novel approach to automatically synthesize synchronization code for concurrent programs. By allowing programmers to write code assuming a simple, non-preemptive scheduler, the system automatically inserts necessary synchronization to ensure correctness under a preemptive scheduler, without introducing deadlocks. This method is demonstrated to be efficient and effective, even finding previously missed concurrency bugs.
What Problem Does This Paper Address?
Writing correct concurrent programs is notoriously difficult. A major challenge stems from preemptive schedulers, which can interrupt threads at any time, leading to race conditions and deadlocks. Traditional approaches often require explicit, detailed specifications (like assertions) to ensure correctness, which can be hard to write completely and accurately. This paper addresses the problem of automatically generating correct concurrent programs by easing the specification burden. Instead of explicit specifications, it leverages an implicit specification: the program's behavior under a friendly, non-preemptive scheduler is considered the "correct" behavior. The goal is to synthesize synchronization mechanisms (like locks) that make the program behave identically under a preemptive scheduler as it would under a non-preemptive one, effectively transforming a program written for a simpler model into one safe for a more complex, realistic execution environment.
Methods
The core of the proposed solution involves several key techniques:
- Implicit Specification via Non-Preemptive Scheduling: Programmers write code assuming a non-preemptive scheduler, where threads only yield control voluntarily. This simplifies reasoning about concurrency.
- Finitary Abstraction: To handle potentially infinite state spaces of concurrent programs, the authors introduce a data-oblivious abstraction. This abstraction tracks memory accesses (reads/writes) and branching choices but ignores actual data values. This allows for more tractable analysis.
- Reduction to Language Inclusion: The problem of ensuring preemption-safety is reduced to checking language inclusion between two non-deterministic finite automata (NFAs). One NFA represents the abstract program under preemptive scheduling, and the other represents it under non-preemptive scheduling. The goal is to ensure that all behaviors of the preemptive version are "covered" by the non-preemptive version, modulo an independence relation.
- Bounded Language Inclusion Modulo an Independence Relation: The standard language inclusion problem is undecidable. The authors adapt an antichain-based algorithm to handle a bounded version of language inclusion modulo an independence relation, making the problem decidable in practice.
- Counterexample-Guided Inductive Synthesis (CEGIS): The system iteratively finds counterexamples (traces that are valid under preemptive but not non-preemptive scheduling) and uses them to infer mutual exclusion (mutex) constraints. These constraints are then enforced, and the process repeats until language inclusion holds.
- Global Lock Placement Constraints and MaxSMT: Once mutex constraints are identified, they are formulated as global constraints. An objective function (e.g., minimizing lock statements for coarse-grained locking, or maximizing concurrency for fine-grained locking) is used to find an optimal lock placement by encoding the problem as a MaxSMT (Maximum Satisfiability Modulo Theories) problem.
Datasets
The paper evaluates its approach on a set of benchmarks, including:
- ConRepair benchmarks: A set of benchmarks previously used for assertion-based synthesis.
- CPMAC driver benchmark: Based on a Linux driver for a TI AR7 CPMAC Ethernet controller, artificially injected with concurrency bugs.
- Memcached benchmark: A fragment of the memcached key-value store, used to synthesize locking from scratch.
The authors note that they preprocess these benchmarks by eliminating assertions and replacing assume statements with await to fit their model.
Key Insights and Ideas
- Implicit Specification is Powerful: Using non-preemptive scheduling as an implicit specification significantly simplifies the programmer's task while still enabling robust synchronization synthesis. This is a key differentiator from methods requiring explicit assertions.
- Abstraction is Crucial for Scalability: The data-oblivious abstraction is essential for making the analysis tractable for real-world systems, even though it might introduce some imprecision.
- Language Inclusion Modulo Independence is the Right Framework: Reducing preemption-safety to this specific type of language inclusion problem provides a solid theoretical foundation for the synthesis process.
- CEGIS with Global Constraints is Better than Greedy: Inferring global mutex constraints iteratively, rather than placing locks greedily, leads to more optimal lock placements and avoids suboptimal solutions.
- Objective Functions Enable Tailored Solutions: The ability to optimize lock placements based on coarse-grained (fewer locks) or fine-grained (more concurrency) objectives allows for tailoring the synthesized code to specific performance needs.
Key Results
- Effectiveness: The tool (Liss) successfully detected and fixed concurrency bugs in several benchmarks, including one previously missed by explicit specification-based tools. It also found a new race condition in the
usb-serialfamily of benchmarks. - Efficiency: The synthesis procedure, particularly the language inclusion check, was significantly faster than previous approaches (e.g., using CBMC model checker), running orders of magnitude faster on complex examples.
- Precision of Abstraction: The coarse abstraction proved surprisingly precise for systems code, requiring manual refinement in only a few instances across all benchmarks.
- Optimal Lock Placement: The system successfully synthesized deadlock-free lock placements for both coarse-grained and fine-grained objectives, demonstrating the quality of the synthesized solutions. For example, the CPMAC benchmark required significantly fewer locks with the coarse-grained objective compared to no objective function.
Limitations and Future Work
- Manual Abstraction Refinement: While the abstraction is generally precise, manual refinement was sometimes needed to avoid unnecessary synchronization, particularly when dealing with return values or pointer aliasing.
- Handling Recursive Programs and Alias Analysis: The current implementation does not handle recursive programs and lacks sophisticated alias analysis, which can lead to unsound abstractions.
- Performance for Very Large Systems: While efficient, handling extremely large real-world systems might require further performance improvements.
- Future Work: The authors suggest extending the method with automatic abstraction refinement. They also propose optimizing lock placement not just syntactically but by profiling actual program performance on a specific system, adjusting locking strategies based on contention measurements.
Summary updated