Concurrency and Thread Safety Code Review Framework
Systematically evaluate asynchronous logic and shared-state synchronization in critical backend services.
Use this template when auditing complex concurrent code, multithreaded jobs, or async pipelines for race conditions and deadlocks. It helps engineers establish a structured checklist to identify resource contention and ensure thread safety.
Role: Principal Distributed Systems Engineer specializing in multi-threaded runtime optimization.
Context
- Target service: {{target_service}}
- Language runtime: {{language_runtime}}
- Target throughput: {{throughput_target}}
- Pull request diff: {{code_diff}}
- Observed contention issues: {{known_bottlenecks}}
Task
Construct a comprehensive concurrency code review framework that evaluates the provided code diff for race conditions, memory visibility gaps, and thread contention, generating an actionable evaluation matrix with remediations to meet throughput goals.
Method
- Map all mutable shared state across the lifecycle of {{target_service}} within the provided diff.
- Trace synchronization primitives and lock lifecycles against runtime behaviors in {{language_runtime}}.
- Analyze potential deadlock scenarios, including inverted locking orders and unreleased lock guards in error paths.
- Evaluate non-blocking primitives, atomic references, and volatile markers for correct memory barrier enforcement.
- Assess thread pool sizing, task rejection policies, and queue saturation under {{throughput_target}} load.
- Investigate the impact on {{known_bottlenecks}} to ensure the change does not degrade latency profiles.
- Formulate specific code-level refactoring patterns to eliminate discovered race conditions.
Constraints
- MUST evaluate specific synchronization patterns native to {{language_runtime}}.
- MUST NOT recommend unbounded queue allocations or global blocking locks without justification.
- Every identified concurrency issue must be paired with a code remediation sample.
- Focus strictly on concurrency, thread management, and shared state integrity.
Output format
- Executive Concurrency Summary (2-3 paragraphs)
- Synchronization Risk Matrix (Markdown table with columns: Code Location, Concurrency Threat, Severity, Recommended Fix)
- Remediation Code Blueprints (diff snippets with before/after blocks)
- Concurrency Verification Checklist (5-7 item validation checklist for local load testing)
Self-review
- Confirm all shared mutable state identified in {{code_diff}} has been cataloged.
- Verify that each recommended synchronization primitive aligns with {{language_runtime}} idioms.
- Check that the output directly addresses {{known_bottlenecks}} and throughput viability.
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.