race-conditions

Identify and mitigate race conditions using atomic operations and synchronization patterns.

13|2|Updated Jan 21, 2026
One-click install
npx skills add https://github.com/yanko-belov/code-craft --skill race-conditions-yanko-belov
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: race-conditions
Source: https://github.com/yanko-belov/code-craft/tree/main/skills/race-conditions
Command: npx skills add https://github.com/yanko-belov/code-craft --skill race-conditions-yanko-belov

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Race conditions arise when correctness depends on timing, causing intermittent bugs under concurrent operations. This Skill guides you to recognize, prevent, and fix these issues with proven patterns.

Core Features & Use Cases

  • Atomic operations and transactions to guarantee consistency under concurrent access.
  • Locking strategies (distributed locks, pessimistic/optimistic locking) to coordinate updates.
  • Idempotency and versioning approaches to prevent duplicate or conflicting work.
  • Real-world scenarios across databases, microservices, and async systems.

Quick Start

  • Identify shared mutable state accessed by multiple actors and replace read-then-write patterns with atomic updates or transactional boundaries.
  • Introduce versioning and optimistic locking where conflicts are likely; add distributed locks for complex multi-resource operations.
  • Implement idempotency keys for duplicate requests and design tests that simulate concurrent executions.

Frequently Asked Questions about race-conditions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent race conditions in concurrent database transactions?

Prevent race conditions in concurrent database transactions by replacing read-then-write patterns with atomic updates and enforcing transactional boundaries. This guarantees consistency when multiple actors access shared mutable state simultaneously.

What is the difference between optimistic and pessimistic locking strategies?

Optimistic locking uses versioning to detect conflicts at commit time, while pessimistic locking restricts access immediately. Both locking strategies coordinate concurrent updates to prevent race conditions in multi-threaded and distributed environments.

How do I implement idempotency checks for duplicate API requests?

Implement idempotency checks for duplicate API requests by assigning unique idempotency keys to each operation. This prevents duplicate or conflicting work when the same request is received multiple times in asynchronous systems.

When do I need distributed locks for multi-resource operations?

You need distributed locks for multi-resource operations when complex updates span multiple microservices or databases. They coordinate access across distributed environments where local transaction boundaries are insufficient to prevent race conditions.

How do I test for race conditions and timing bugs?

Test for race conditions and timing bugs by designing tests that simulate concurrent executions. Identify shared mutable state accessed by multiple actors and verify that atomic operations and synchronization mechanisms maintain correctness under concurrency.

How do I fix intermittent bugs caused by concurrent access to shared state?

Fix intermittent bugs caused by concurrent access by identifying shared mutable state and replacing read-then-write patterns with atomic updates. Introduce versioning, optimistic locking, and idempotency checks to ensure correctness under concurrency.