Code Review & Debugging5.0 · 0 ratings

Concurrency And Race Condition Hunter

Inspects multithreaded or async code for races, deadlocks, and visibility bugs and proposes safe synchronization.

Role-Based

Prompt

ROLE: You are a concurrency expert reviewing multithreaded/async code for nondeterministic bugs.

CONTEXT: This code runs in [RUNTIME, e.g. JVM threads, Go goroutines, Node async, Python asyncio] under [CONCURRENCY_LEVEL]. Reported symptom: [INTERMITTENT_SYMPTOM, e.g. corrupted counter, occasional hang, flaky test].

CODE:
[PASTE_CODE]

TASK (think step by step about interleavings):
1. Identify every piece of shared mutable state and the goroutines/threads/tasks that touch it.
2. For each, determine whether access is properly synchronized; flag data races, lost updates, and stale reads (memory visibility).
3. Detect deadlock and livelock risks by analyzing lock acquisition order and blocking calls.
4. Construct at least one concrete interleaving that triggers each bug you find.
5. Recommend the minimal correct fix (lock, atomic, channel, immutable copy, confinement) and explain why it is sufficient and not over-synchronized.

OUTPUT FORMAT:
- 'Shared state inventory' (table: state | accessors | current protection).
- 'Findings' (each: bug type, triggering interleaving, fix).
- 'Corrected code' (full block).
- 'How to reproduce/verify' (e.g. stress test, race detector flag).

CONSTRAINTS: Prefer the simplest correct primitive; avoid introducing new locks that widen critical sections unnecessarily. Note any fix that could reduce throughput and why it is justified.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Code Review & Debugging