Skip to content
Back to skills

Concurrency Primitives

ASecurity

Use locks, atomics, channels, and barriers correctly, and know which class of bug each prevents. Use when writing code that shares state between threads.

  • 7 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
ai-agentstesting

Security analysis

A100/100

Scanned September 5, 2026

npx -y skills add Amey-Thakur/AI-SKILLS --skill concurrency-primitives --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Concurrency Primitives?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Concurrency Primitives
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/amey-thakur-concurrency-primitives/badge)](https://www.skillsdirectory.com/skills/amey-thakur-concurrency-primitives)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: concurrency-primitives
description: Use locks, atomics, channels, and barriers correctly, and know which class of bug each prevents. Use when writing code that shares state between threads.
---

# Concurrency primitives

Shared mutable state without synchronisation produces bugs that appear
under load, vanish under a debugger, and cannot be reproduced. The
primitives are few and the discipline of using them consistently is the
whole difficulty.

## Method

1. **Prefer not sharing.** Immutable data, message passing, and
   per-thread state eliminate whole classes of bug rather than managing
   them (see process-and-threads).
2. **Protect invariants, not variables.** A lock guards a set of state
   that must stay consistent together; locking each field separately
   protects nothing meaningful.
3. **Establish a lock ordering and keep it.** Deadlock comes from two
   threads acquiring the same locks in different orders, and a global
   ordering rule prevents it entirely.
4. **Hold locks briefly and never across input or output.** A lock held
   during a network call serialises the whole system on that call's
   latency.
5. **Use atomics for single values only.** They are cheap and correct
   for counters and flags, and they do not compose into multi-variable
   invariants.
6. **Prefer channels and queues for handoff.** Transferring ownership is
   easier to reason about than shared access, and it makes the
   concurrency visible in the design.
7. **Test concurrency deliberately.** Race detectors, stress under
   contention, and deterministic interleaving tests, because normal
   tests pass on broken concurrent code (see concurrency-testing).

## Boundaries

Correct primitives do not guarantee correct design; a race-free program
can still have a logical race in its business rules. Lock-free
programming is subtle enough that library implementations should be
preferred. Memory models differ between languages and hardware in ways
that matter for low-level code.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…