Abstract
Multithreaded programming is notoriously difficult due to nondeterminism, where identical inputs can yield different thread interleavings. While existing Deterministic Multithreading (DMT) systems address this by enforcing a single schedule for a specific input, they suffer from instability—minor variations in input or environment can lead to drastically different execution paths. This paper introduces TERN, a "stable" DMT system that employs schedule memoization to cache and reuse successful thread interleavings. By utilizing symbolic execution to identify input constraints and a windowing mechanism for continuous server requests, TERN ensures consistent behavior across similar executions, facilitating easier bug reproduction and more predictable performance.
The Challenge of Nondeterminism and Instability
Multithreaded programming is difficult because of nondeterminism. Two runs of the same program with the same input might produce different results because the OS or hardware interleaves threads differently. While existing DMT systems (like CoreDet or Kendo) solve this by forcing the same schedule for the same input, they suffer from the instability problem.
Because these systems are "stateless," a tiny change—like a different processor type, a minor input variation, or a different library version—can force the program into a completely different thread schedule. If a bug only appears in one specific schedule, it becomes nearly impossible to reproduce across different machines. Furthermore, most DMT systems struggle with server applications where inputs arrive continuously and timing is unpredictable.
The TERN Approach: Stability through Memoization
TERN shifts the focus from just being deterministic to being stable. The core innovation is Schedule Memoization, where TERN maintains a cache of <Input Constraints, Schedule> tuples. When a new input arrives, TERN checks if it satisfies the constraints of a previously recorded schedule. If it does, TERN reuses that schedule rather than calculating a new one.
Key Components
- Symbolic Execution (KLEE): To determine which inputs actually affect thread scheduling, TERN uses a modified version of the KLEE symbolic execution engine. It tracks branch outcomes to see which parts of the input (e.g., the number of threads or request types) dictate the synchronization order.
- Windowing for Servers: To handle continuous request streams in servers like Apache, TERN splits the stream into "windows." It processes a batch of requests, lets the system reach a quiescent state, and then moves to the next window. This makes long-running servers look like a series of repeatable batch programs.
- The Replayer and Memoizer: TERN operates as a user-space scheduler. The Memoizer records new schedules and their constraints (often running offline), while the Replayer efficiently enforces cached schedules using "semaphore relay" to minimize synchronization overhead.
Evaluation and Key Results
The authors evaluated TERN on 14 diverse programs, including server applications (Apache, MySQL), batch processing (PBZip2), and scientific benchmarks (SPLASH2).
- High Reuse Rates: TERN achieved a 90.3% reuse rate for the Apache web trace using only 100 memoized schedules. For PBZip2, the reuse rate was 96.2%.
- Bug Reproduction: In tests with known concurrency bugs in SPLASH2, TERN consistently reproduced (or avoided) the bugs across different inputs, whereas existing DMT systems saw the bugs disappear or appear randomly when inputs changed slightly.
- Low Overhead: For 9 out of 14 programs, the overhead was negligible or even negative (speedup). The highest overhead recorded was 39.1%, which is acceptable for the gain in stability.
- Ease of Use: Adapting most programs to TERN required modifying only 3–10 lines of code, primarily to mark which input variables should be treated as symbolic.
Key Insights
- Stability > Determinism: For developers, a system that reuses a "known" schedule is more valuable than one that generates a "new" deterministic schedule every time. Reusing schedules avoids "venturing into unfamiliar, potentially buggy territory."
- Input Constraints are Often General: Many different inputs can share the same schedule. For example, in PBZip2, the actual content of the file doesn't affect how threads interleave; only the number of blocks and threads matters.
- Performance via Skipping: Because TERN enforces a strict total order, it can skip some original synchronization operations (like
usleepor certain barriers) during replay, sometimes resulting in speedups.
Limitations
While effective, TERN requires manual annotation to identify "symbolic" inputs. The memoization process using symbolic execution is also slow (up to 200x), though this is mitigated by running it as a background process. Additionally, the underlying KLEE engine has difficulty with floating-point math, and TERN's "slicing" optimization is technically unsound, though it works well in practice.
Summary updated