PlaybookPrompts

Spot and fix race conditions in concurrent code

Coding & Development concurrencydebuggingcode-review

Race conditions are notoriously hard to reproduce and diagnose. This prompt walks an LLM through auditing a concurrent code block for shared-state hazards and proposing safe alternatives.

Prompt
You are a senior engineer specializing in concurrency. Audit the following code for race conditions and shared-state hazards.

Language / runtime: {{LANGUAGE_AND_RUNTIME}}
Code block:
```
{{CODE_BLOCK}}
```

Follow these steps:
1. List every shared resource (variables, files, caches, DB connections) that multiple threads or coroutines touch.
2. For each shared resource, describe the specific sequence of events that could cause a race condition. Be concrete — name the interleaving, not just 'two threads write at the same time'.
3. Rate each hazard: Critical (data corruption or crash), Moderate (stale reads, wrong results), Low (cosmetic inconsistency).
4. Propose a fix for each Critical and Moderate hazard. Prefer the least-invasive option (a lock, an atomic operation, a queue handoff) and explain the trade-off.
5. If no race conditions exist, explain why the code is safe — do not invent problems.
6. Flag any patterns that are safe today but fragile if concurrency increases (e.g., single-threaded event loop assumptions).
Variables to fill in
  • {{LANGUAGE_AND_RUNTIME}}
  • {{CODE_BLOCK}}

How to use this prompt

  1. Copy the prompt above (Copy button on the top-right).
  2. Replace each {{VAR}} with your own value. Variables: {{LANGUAGE_AND_RUNTIME}}{{CODE_BLOCK}}.
  3. Paste it into one of the recommended tools below.
  4. Iterate: tighten constraints in the prompt if the output is generic.

Why this prompt is structured this way

The prompt is split into explicit steps because LLMs do better when the path is named, not implied. Each variable forces specificity at the input layer — vague inputs get vague outputs.

Heads up: some of the links on this page are affiliate links — meaning we may earn a commission if you sign up after clicking, at no extra cost to you. We only recommend tools we'd put on our own stack. You can see our full affiliate disclosure here.

Pair this prompt with a tool

The PlaybookPrompts weekly

One short email per week. The five sharpest prompts we found, one tool worth your attention, one anti-pattern to avoid. Unsubscribe in one click.

Newsletter signup is not configured. Set PUBLIC_NEWSLETTER_USERNAME in the build env.