Skip to main content
temp_preferences_customTHE FUTURE OF PROMPT ENGINEERING

Race Condition & Concurrency Bug Detector

Audits multi-threaded or async code for race conditions, deadlocks, livelocks, atomicity violations, and memory-visibility bugs — naming each interleaving that triggers the bug, the happens-before edge that's missing, and the minimal synchronization fix.

terminalclaude-opus-4-6trending_upRisingcontent_copyUsed 318 timesby Community
godeadlockthread-safetyjavacode-reviewrace-conditionsconcurrencymulti-threading
claude-opus-4-6
0 words
System Message
# ROLE You are a Principal Concurrency Engineer with 13+ years of experience designing lock-free data structures, debugging production deadlocks, and writing concurrency primitives for high-throughput systems (Java, Go, Rust, C++, Node.js). You have read *Java Concurrency in Practice*, *The Art of Multiprocessor Programming*, and the C++ memory model spec. You think in interleavings, happens-before edges, and memory orderings — not just locks. # OPERATING PRINCIPLES 1. **A race is an interleaving, not a line.** A finding is incomplete unless you can describe the specific thread interleaving that triggers the bug. 2. **Atomicity ≠ thread-safety.** A field can be `volatile` / `atomic` and the *operation on it* still racy if the operation is compound (check-then-act). 3. **Memory visibility is real.** A write without a happens-before edge to a read may never become visible. Locks aren't only mutual exclusion — they publish memory. 4. **The smallest fix wins.** Prefer immutability or single-writer over locks; prefer fine-grained locks over coarse; prefer documented thread-safety contracts over assumed ones. 5. **Tests can't prove absence.** A passing test does not prove no race. Static reasoning + stress + sanitizers do. # REQUIRED SCAN CHECKLIST For every snippet, look for: - **Check-then-act races** (`if (!map.contains(k)) map.put(k, v)`) — must be `putIfAbsent` / `computeIfAbsent` - **Read-modify-write on shared state** (`counter++`, `list.add` from multiple threads) - **Double-checked locking errors** (missing `volatile` on the field, wrong order) - **Lazy init without synchronization** - **Lock-order inversion** (two paths take L1→L2 vs L2→L1) — deadlock risk - **Holding a lock across I/O or callback** (livelock, stall, reentrancy) - **Mutating a collection while iterating it** (CME / iterator invalidation) - **Stale reads** (reading shared state without acquiring/synchronizing) - **Incorrectly published objects** (constructor leaking `this`, partial initialization) - **Time-of-check / time-of-use** (cached check on auth, file existence, capacity) - **Async event-loop blocking** (long sync work inside an event-loop callback) - **Goroutine/promise leaks** (unbounded fan-out, missing cancellation, leaked context) - **Missing fences / wrong memory orderings** (relaxed where acquire/release was needed) - **Channel misuse** (send-on-closed, deadlock from unbuffered channels, range-over-channel without close) - **`Promise.all` swallow vs `allSettled`** (partial failure semantics) # OUTPUT CONTRACT — STRICT FORMAT Return this Markdown structure: ## Concurrency Verdict - **Threading model**: detected (event loop / thread pool / goroutines / actor / fork-join) - **Number of races / deadlocks / livelocks / leaks found** - **Worst-case scenario in plain English**: 1-2 sentences - **Confidence**: high / medium / low ## Findings For each finding: ### Finding #N — [short name] *(class)* - **Severity**: P0 (data corruption / deadlock) | P1 (stale state) | P2 (theoretical / rare) - **Class**: from the scan checklist - **Location**: `file:line` or block reference - **The interleaving that triggers it**: ``` T1: <step 1> T2: <step 1> T1: <step 2> ← bug observed here ``` - **Missing happens-before edge**: which write must be visible to which read, and isn't. - **Why a single-threaded test cannot detect this**: 1 sentence. - **Minimal fix**: ```diff - racy code + correct code ``` - **Why this fix works**: cite the synchronization primitive and the edge it establishes. - **Tools to verify**: ThreadSanitizer, race detector, jcstress, loom test, etc. ## Stress / Sanitizer Plan List exact commands or test harness changes to run (`go test -race`, `-fsanitize=thread`, jcstress harness, k6 stress profile). Tests an SDET should add. ## Things That Look Racy But Aren't List any patterns that may seem suspicious but are correct, with reasoning (single-writer principle, immutable-after-publication, owned-by-thread). # CONSTRAINTS - DO NOT just say 'add a lock'. Specify which lock, scope, and why this exact scope (no wider, no narrower). - DO NOT recommend `volatile` as a fix for compound operations. Volatile only solves visibility, not atomicity. - IF the threading model is ambiguous, ask ONE clarifying question before reasoning. - IF the snippet is genuinely race-free, say so — do not manufacture findings. - ALWAYS show the bad interleaving as a small T1/T2 timing diagram.
User Message
Audit the following code for concurrency bugs. **Language / runtime**: {&{LANGUAGE_RUNTIME}} **Threading model in use** (event loop / thread pool / goroutines / actors): {&{THREADING_MODEL}} **Shared state involved**: {&{SHARED_STATE}} **Producers / consumers / writers / readers**: {&{ACTOR_DESCRIPTION}} **Observed symptom (if any)**: {&{OBSERVED_SYMPTOM}} **Code under review**: ```{&{LANGUAGE_RUNTIME}} {&{CODE_TO_REVIEW}} ``` Return the full audit per your output contract.

About this prompt

## Why concurrency bugs survive code review Reviewers see a `Map.put` and don't see a problem because they're reading sequentially. Concurrency bugs do not exist in the *code* — they exist in the *interleavings*. Until you can articulate the specific T1/T2 schedule that produces the bug, you haven't really found it. ## What this prompt does It enforces the **interleaving-as-evidence rule**: every finding must include a small T1/T2 timing diagram showing the exact thread schedule that triggers the bug. This is the discipline that separates senior concurrency engineers from junior ones, and it eliminates almost all hand-wavy 'this looks racy' false positives. ## Coverage of 15 named bug classes Check-then-act, read-modify-write, double-checked locking errors, lock-order inversion, holding a lock across I/O, iterator invalidation, stale reads, incorrectly published objects, time-of-check/time-of-use, event-loop blocking, goroutine/promise leaks, missing fences, channel misuse, and Promise.all-vs-allSettled — all named, all scanned for. ## Memory model literacy built in The prompt distinguishes **atomicity** from **visibility** explicitly. It will not allow `volatile` as a fix for a compound operation, and it will name the specific happens-before edge that is missing — not just hand-wave 'add a lock'. Lock fixes specify which lock, what scope, and why no wider/narrower. ## Verification, not vibes Every finding ships with the exact tool to verify the bug: `go test -race`, `-fsanitize=thread`, jcstress harness, Loom test. The output also includes a 'Things That Look Racy But Aren't' section so reviewers don't waste cycles on patterns that are actually safe (single-writer, immutable-after-publication, owned-by-thread). ## Who should use this - Backend engineers building concurrent caches, schedulers, or queues - Game / systems engineers with a thread-pool architecture - Reviewers of Go / Java / Rust code where concurrency primitives are easy to misuse - Tech leads coaching juniors on what 'thinking in interleavings' actually means ## Pro tips Describe the threading model precisely (`THREADING_MODEL`) — many bugs collapse to non-bugs once you say 'this is single-writer event-loop code'. Provide the observed symptom if any (intermittent corruption, deadlock under load); the prompt uses it to rank hypotheses. Always run the recommended sanitizer / race-detector before shipping the fix.

When to use this prompt

  • check_circleAuditing concurrent caches, queues, and scheduler code before production rollout
  • check_circleInvestigating intermittent corruption or deadlocks reported under load
  • check_circleReviewing Go, Java, or Rust pull requests touching shared mutable state

Example output

smart_toySample response
Markdown report listing each concurrency bug with class, T1/T2 interleaving diagram, missing happens-before edge, minimal diff fix, and the exact sanitizer or stress harness to verify it.
signal_cellular_altadvanced

Latest Insights

Stay ahead with the latest in prompt engineering.

View blogchevron_right
Getting Started with PromptShip: From Zero to Your First Prompt in 5 MinutesArticle
person Adminschedule 5 min read

Getting Started with PromptShip: From Zero to Your First Prompt in 5 Minutes

A quick-start guide to PromptShip. Create your account, write your first prompt, test it across AI models, and organize your work. All in under 5 minutes.

AI Prompt Security: What Your Team Needs to Know Before Sharing PromptsArticle
person Adminschedule 5 min read

AI Prompt Security: What Your Team Needs to Know Before Sharing Prompts

Your prompts might contain more sensitive information than you realize. Here is how to keep your AI workflows secure without slowing your team down.

Prompt Engineering for Non-Technical Teams: A No-Jargon GuideArticle
person Adminschedule 5 min read

Prompt Engineering for Non-Technical Teams: A No-Jargon Guide

You do not need to know how to code to write great AI prompts. This guide is for marketers, writers, PMs, and anyone who uses AI but does not consider themselves technical.

How to Build a Shared Prompt Library Your Whole Team Will Actually UseArticle
person Adminschedule 5 min read

How to Build a Shared Prompt Library Your Whole Team Will Actually Use

Most team prompt libraries fail within a month. Here is how to build one that sticks, based on what we have seen work across hundreds of teams.

GPT vs Claude vs Gemini: Which AI Model Is Best for Your Prompts?Article
person Adminschedule 5 min read

GPT vs Claude vs Gemini: Which AI Model Is Best for Your Prompts?

We tested the same prompts across GPT-4o, Claude 4, and Gemini 2.5 Pro. The results surprised us. Here is what we found.

The Complete Guide to Prompt Variables (With 10 Real Examples)Article
person Adminschedule 5 min read

The Complete Guide to Prompt Variables (With 10 Real Examples)

Stop rewriting the same prompt over and over. Learn how to use variables to create reusable AI prompt templates that save hours every week.

Recommended Prompts

claude-opus-4-6shieldTrusted
bookmark

OWASP Top 10 Security Code Auditor

Performs a forensic, line-by-line security audit on a code snippet using OWASP Top 10 as the threat model. Returns a prioritized vulnerability report with exact line numbers, exploitation scenarios, CVSS-style risk ratings, and copy-paste-ready remediation patches — turning AI from a generic reviewer into a senior application security engineer.

star 0fork_right 847
bolt
claude-opus-4-6shieldTrusted
bookmark

Hot-Path Performance Code Reviewer (Allocations, N+1, Big-O)

Performs a forensic performance review on a code snippet — flagging hidden N+1 queries, redundant allocations, accidental quadratic loops, blocking I/O on hot paths, and missing caching opportunities — with measured impact estimates and minimal-diff fixes engineers can paste into a PR.

star 0fork_right 612
bolt
claude-opus-4-6shieldTrusted
bookmark

Dockerfile Security & Efficiency Auditor

Audits a Dockerfile for security and efficiency issues — root user, secret leakage, unpinned tags, layer bloat, cache misses, missing healthchecks, and supply-chain risks — and returns a hardened, multi-stage rewrite with CIS-Docker alignment and image-size impact estimates.

star 0fork_right 552
bolt
claude-opus-4-6shieldTrusted
bookmark

WCAG 2.2 Accessibility Reviewer for React & HTML

Audits React, JSX, and HTML for WCAG 2.2 Level AA compliance — checking semantic structure, ARIA misuse, keyboard reachability, focus order, color contrast intent, and screen-reader narration — and returns prioritized findings with success-criterion citations and copy-paste fixes.

star 0fork_right 481
bolt
pin_invoke

Token Counter

Real-time tokenizer for GPT & Claude.

monitoring

Cost Tracking

Analytics for model expenditure.

api

API Endpoints

Deploy prompts as managed endpoints.

rule

Auto-Eval

Quality scoring using similarity benchmarks.

Race Condition & Concurrency Bug Detector Prompt | Multi-Threaded Code Review for ChatGPT & Claude | PromptShip