Spot and fix race conditions in concurrent code
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.
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). {{LANGUAGE_AND_RUNTIME}}{{CODE_BLOCK}}
How to use this prompt
- Copy the prompt above (Copy button on the top-right).
- Replace each
{{VAR}}with your own value. Variables:{{LANGUAGE_AND_RUNTIME}}{{CODE_BLOCK}}. - Paste it into one of the recommended tools below.
- 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.
Pair this prompt with a tool
Cursor
$20/moAI-first code editor forked from VS Code.
Cursor is VS Code with first-class LLM integration. Multi-file edits, codebase Q&A, autocomplete that's actually useful. The default IDE for many shipping engineers in 2026.
Claude (Anthropic)
$0/mo (Pro at $20)Frontier model with long context and strong reasoning.
Claude (Opus / Sonnet / Haiku tiers) is the assistant favored by writers and engineers who care about reasoning quality and tone. 1M token context on Opus.
ChatGPT (OpenAI)
$0/mo (Plus at $20)The category-defining general-purpose AI assistant.
ChatGPT has the broadest feature surface: image gen, voice, custom GPTs, web browsing, code execution. Often the right default; sometimes beaten on specific tasks by Claude or Perplexity.
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.