Concurrency and race condition review
Paste code along with its concurrency model and the shared state involved for a review that skips general code-review concerns entirely and focuses only on concurrency. - Race conditions from unsynchronized read-modify-write or check-then-act patterns - Deadlock or livelock risk from lock ordering across threads or async tasks - Cleanup gaps under concurrent cancellation or failure - Each issue ships with the exact interleaving that triggers it, not a generic warning
Review this code specifically for concurrency issues: Code: {{code}} Concurrency model: {{model}} Shared state involved: {{state}} Check for: 1. Race conditions on shared state (read-modify-write without synchronization, check-then-act bugs). 2. Deadlock or livelock risk from lock ordering or nested locking. 3. Unsafe assumptions about ordering, atomicity, or visibility of writes across threads/tasks. 4. Resources that need but lack proper cleanup under concurrent cancellation or failure. 5. Whether a lock-free or higher-level primitive (queue, immutable data, actor) would remove the need for manual locking entirely. For each issue, give: the specific interleaving that triggers it, its severity, and a concrete fix.