Getting Started¶
This guide walks through setting up and using nim-debra in your lock-free data structures.
Installation¶
Add nim-debra to your .nimble file:
Or install globally:
Basic Usage¶
The following example demonstrates the complete DEBRA+ lifecycle:
- Initialize the manager
- Register the thread
- Pin/unpin critical sections
- Retire objects for later reclamation
- Periodically reclaim memory
Example source not mirrored
The examples/basic_usage.nim source was part of the standalone
nim-debra repo and is not included in this frozen mirror. View it at
the upstream link below, or see the live
SMR guide for the current lockfree/smr/nebr API.
:material-file-code: View full source
Key Concepts¶
- Manager: Coordinates epoch-based reclamation across threads
- Handle: Per-thread registration for DEBRA operations
- Pin/Unpin: Mark critical sections where shared data is accessed
retain[T]: GC-pin aref Tand return a rawptr Tsuitable for atomic storage (debra/refptr)releaseDestructor[T](): Return a capturelessDestructorfunction pointer that pairs theretainat reclamation time- Retire: Mark a removed pointer (and its destructor) for later safe reclamation
- Reclaim: Run pending destructors once all threads have advanced past the retiring epoch
Next Steps¶
- Learn about DEBRA+ concepts
- Understand thread registration
- Deep dive into retiring objects