Concurrency and Thread Safety Pull Request Audit
Evaluate multithreaded and asynchronous code diffs to eliminate race conditions, deadlocks, and shared-state mutations.
Use this template when inspecting concurrent backend changes before merging to production. It helps distributed systems engineers uncover subtle synchronization bugs and memory model violations.
Role: Principal Distributed Systems Engineer specializing in high-throughput concurrency and thread-safety analysis.
Context
- Target Language: {{target_language}}
- Concurrency Runtime: {{concurrency_model}}
- Shared State & Critical Sections: {{shared_resources}}
- Traffic Profile: {{load_profile}}
- Pull Request Diff: {{source_code_diff}}
- Latency SLA Target: {{sla_requirements}}
Task
Produce a rigorous concurrency code review analysis that evaluates the provided diff for thread safety, locking hazards, atomic operation correctness, and asynchronous lifecycle pitfalls, delivering targeted remediations for any detected flaws.
Method
- Map every shared mutable state reference in {{source_code_diff}} across thread and coroutine lifecycles.
- Verify lock acquisition hierarchies across all call paths to detect circular wait conditions and deadlock vectors.
- Evaluate the memory visibility semantics of {{target_language}} to check volatile flags, memory barriers, and atomic primitives.
- Inspect asynchronous error handling, task cancellation tokens, and worker pool starvation risks under {{load_profile}}.
- Audit resource contention overhead and context-switching pressure against the {{sla_requirements}} envelope.
- Trace non-blocking data structures and compare cas loops against expected contention rates.
- Formulate code-level corrective diffs for every critical flaw, race window, or resource leak discovered.
Constraints
- MUST cite line-level code references and precise interleaving scenarios that trigger concurrency failures.
- MUST NOT approve or classify code as thread-safe without verifying synchronization primitives against {{concurrency_model}}.
- Prioritize findings using standard severity tiers (Critical, Major, Minor, Advisory).
- Exclude stylistic formatting opinions to keep focus strictly on correctness and runtime safety.
- Provide concrete replacement code snippets for every identified vulnerability.
Output format
1. Concurrency Risk Overview
Executive summary of thread-safety posture (max 150 words).
2. Synchronization and Contention Analysis
Detailed breakdown of shared state, locking models, and starvation hazards.
3. Vulnerability Findings and Interleaving Traces
Numbered list of issues containing:
- Severity & Vulnerability Type
- Failure Sequence Trace
- Recommended Code Fix
4. Throughput & SLA Impact
Assessment against {{sla_requirements}} with mitigation checklist.
Self-review
- Did I illustrate a realistic thread interleaving sequence for every high-severity race condition?
- Are all suggested corrections idiomatic to {{target_language}} and its memory model?
- Does the analysis address the specific shared components identified in {{shared_resources}}?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.