Skip to content
Skills Library
Programming · Testing

concurrency-testing

/concurrency-testing

Force the thread interleavings that expose races by using barriers, stress loops, and linearizability checks instead of hoping the scheduler hits them. Use when testing locks, shared state, or lock-free code where a bug appears once in a thousand runs.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Force the thread interleavings that expose races by using barriers, stress loops, and linearizability checks instead of hoping the scheduler hits them. Use when testing locks, shared state, or lock-free code where a bug appears once in a thousand runs.

Original author description

Force the thread interleavings that expose races by using barriers, stress loops, and linearizability checks instead of hoping the scheduler hits them. Use when testing locks, shared state, or lock-free code where a bug appears once in a thousand runs.

How it works

  1. Method
  2. Signals
  3. Boundaries
Original SKILL.md headings · 51 lines, 420 words
SKILL.md preview
---
name: concurrency-testing
description: Force the thread interleavings that expose races by using barriers, stress loops, and linearizability checks instead of hoping the scheduler hits them. Use when testing locks, shared state, or lock-free code where a bug appears once in a thousand runs.
---

# Concurrency testing

A race condition is a bug a normal test run almost never triggers, because
the scheduler rarely lands two threads in the critical section at the same
instant. Waiting for it to happen by luck means it happens in production
instead. Concurrency testing manufactures the bad interleaving on purpose,
then asserts an invariant that a race would violate.

## Method

1. **Line threads up with a barrier.** Use `threading.Barrier`, a
   `CountDownLatch`, or a `CyclicBarrier` so every worker blocks until all are
   ready, then releases at once. This concentrates them on the critical section
   instead of trickling through it one at a time.
2. **Stress with many threads and iterations, assert an invariant.** Run 16
   threads incrementing a shared counter a million times and assert the total
   equals the expected sum. A short total means a lost update, which means a
   missing lock. Keep the assertion on final state, never on timing.
3. **Turn on the race detector.** Run under `go test -race`, ThreadSanitizer
   (`-fsanitize=thread`), or the JVM's equivalents. These flag unsynchronized
   access on paths your assertions never even reach, and they belong in the CI
   run, not only on a laptop.
4. **Use a deterministic scheduler for the hard cases.** Tools that explore
   interleavings systematically, loom for Rust, jcstress for the JVM, `rr
   chaos` for native code, turn "fails one run in ten thousand" into a
   repeatable failure. Prefer these over sleep-based ordering hacks.
5. **Check linearizability, not just absence of crashes.** Record the
   concurrent history of operations and verify it against a sequential
   specification with Porcupine or Knossos. A structure that never crashes can
   still return a value no legal ordering allows.
6. **Detect deadlock with a timeout, not a hang.** Wrap the run in a hard
   timeout, fail if it expires, and dump every thread's stack. A test that
   hangs forever tells CI nothing; one that times out and prints stacks names
   the cycle.

## Signals

- Does the test fail reliably on a version with the lock removed?
- Does it run under a race detector in CI, not only on a developer's machine?
- On failure, does it report a violated invariant or a thread dump, not just a
  bare timeout?

## Boundaries

This forces and detects races in code under test. Root-causing a specific
deadlock once found is deadlock-analysis, and diagnosing a test whose own setup
races is flaky-test-diagnosis. Some interleavings need a model checker like
TLA+ beyond what a stress test reaches: reach for one when the state space
demands it.

Versions

The database has no other skills named concurrency-testing.

Database snapshot: 13.11.2026 · package version 27d4425757e9 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100race-condition-test-author
    Build deterministic race-condition tests - identify shared mutable state, drive interleavings via barriers / latches / manual scheduling; use ThreadSanitizer (clang `-fsanitize=thread`) for C/C++ data race detection; run the Go race detector end-to-end (`go test -race`, GORACE…
  • 100concurrency-primitives
    Use locks, atomics, channels, and barriers correctly, and know which class of bug each prevents. Use when writing code that shares state between threads.
  • 95rust-concurrency
    Guides concurrency and async decisions in Rust. Use when encountering Send/Sync errors (E0277), choosing between threads vs async, designing shared state, or debugging deadlocks.
  • 100gcd-operations
    Use for iOS/macOS concurrency problems involving dispatch queues, locks, or thread safety. Triggers on: deadlocks (sync on main, nested sync, ABBA lock ordering), thread explosion from too many DispatchQueue.global() calls, data races flagged by Thread Sanitizer (TSan),…
  • 100memory-model
    Use when choosing memory orderings for C++ or Rust atomics, reasoning about happens-before, writing lock-free patterns, or diagnosing data races. Not for lock-based design: use kernel-concurrency.
  • 100go-concurrency
    Use when writing concurrent Go code — goroutines, channels, mutexes, or thread-safety guarantees. Also use when parallelizing work, fixing data races, or protecting shared state, even if the user doesn't explicitly mention concurrency primitives. Does not cover context.Context…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.