agentleFS
rainoftimerainoftime/pl-skills/lock-free-data-structure/SKILL.md

lock-free-data-structure

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Implement lock-free and wait-free data structures for high-concurrency systems.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    CAS Operations: Use compare-and-swap for atomic updates

    line 25
  2. Distinctive:

    Progress Guarantees: Ensure lock-free or wait-free progress

    line 28
  3. Distinctive:

    Use atomic primitives (CAS, FAA) for lock-free code

    line 44
  4. Distinctive:

    Test extensively with thread sanitizers

    line 47
  5. Distinctive:

    Consider using existing libraries (crossbeam, kotlinx)

    line 48
  6. Distinctive:

    When simplicity is more important than performance

    line 86
  7. Distinctive:

    When memory ordering is platform-specific

    line 87
  8. Distinctive:

    Not all algorithms have lock-free versions

    line 93

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Lock-Free Data Structure

Lock-free data structures allow multiple threads to access shared data without using locks, enabling better scalability and avoiding issues like deadlocks and priority inversion.

When to Use This Skill

  • Building high-performance concurrent systems
  • Avoiding lock-related issues (deadlocks, convoying)
  • Real-time systems requiring wait-free guarantees
  • High-contention scenarios
  • Scalable server applications

What This Skill Does

  1. CAS Operations: Use compare-and-swap for atomic updates
  2. Memory Reclamation: Safe memory reclamation (hazard pointers, RCU)
  3. ABA Prevention: Handle ABA problem in lock-free algorithms
  4. Progress Guarantees: Ensure lock-free or wait-free progress
  5. Correctness Verification: Prove linearizability

Key Concepts

ConceptDescription
CASCompare-And-Swap atomic operation
Lock-FreeAt least one thread makes progress
Wait-FreeEvery thread completes in bounded steps
LinearizabilityOperations appear atomic
ABA ProblemValue changes A→B→A, CAS succeeds incorrectly
Hazard PointerSafe memory reclamation scheme

Tips

  • Use atomic primitives (CAS, FAA) for lock-free code
  • Implement safe memory reclamation (hazard pointers, EBR)
  • Be aware of the ABA problem
  • Test extensively with thread sanitizers
  • Consider using existing libraries (crossbeam, kotlinx)

Common Use Cases

  • High-throughput message queues
  • Concurrent caches
  • Real-time trading systems
  • Game engines
  • Database systems

Related Skills

  • concurrency-verifier - Verify correctness
  • message-passing-system - Alternative concurrency model
  • memory-allocator - Lock-free allocators
  • transactional-memory - Alternative to lock-free

Canonical References

ReferenceWhy It Matters
Herlihy & Shavit "The Art of Multiprocessor Programming"Comprehensive treatment
Maged M. Michael & Michael L. Scott "Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Queue Algorithms" (PODC 1996)Classic queue algorithm
Michael "Hazard Pointers: Safe Memory Reclamation for Lock-Free Objects" (TPDS 2004)Memory reclamation

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
Lock-freeNo deadlocks, scalableComplex, ABA issues
Wait-freeGuaranteed progressVery complex
Lock-basedSimpleDeadlocks, contention

When NOT to Use This Skill

  • Low-contention scenarios (locks are fine)
  • When simplicity is more important than performance
  • When memory ordering is platform-specific

Limitations

  • Memory reclamation is tricky
  • ABA problem requires careful handling
  • Not all algorithms have lock-free versions

Assessment Criteria

A high-quality implementation should have:

CriterionWhat to Look For
CorrectnessLinearizable operations
ProgressLock-free or wait-free
SafetyNo use-after-free
PerformanceScales with thread count

Quality Indicators

✅ Good: Linearizable, proper memory reclamation, handles ABA ⚠️ Warning: Works but has memory safety issues ❌ Bad: Race conditions, memory leaks, not actually lock-free

Research Tools & Artifacts

Real-world lock-free data structures:

ToolWhy It Matters
crossbeam (Rust)Lock-free data structures
ConcurrentSkipListJava concurrent skiplist
ConcurrentHashMapJava CHM
boost.lockfreeC++ lock-free
disruptorLMAX Disruptor

Key Libraries

  • crossbeam: Rust concurrency
  • java.util.concurrent: Java concurrent

Research Frontiers

Current lock-free research:

DirectionKey PapersChallenge
Linearizability"Linearizability" (1990)Verification
Epoch-based"Epoch Reclamation"Memory reclamation
Hybrid"Hybrid Reclamation"Combining approaches

Hot Topics

  1. Lock-free for Wasm: WebAssembly concurrency
  2. Quantum lock-free: Quantum data structures

Implementation Pitfalls

Common lock-free bugs:

PitfallReal ExamplePrevention
ABACAS succeeds on reused nodeTag pointers
MemoryUse-after-freeHazard pointers
OrderingWrong memory orderCareful ordering

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.