Skip to content

double-free/double-buffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

double-buffer

Modern cpp lock-free data structure for single-writer-multiple-reader scenarios

Overview

This C++ implementation provides a high-performance, thread-safe data structure designed for scenarios with frequent concurrent reads and infrequent writes. The double buffering technique enables:

  • Completely lock-free read operations (multiple concurrent readers)
  • Block-free write operations (single writer)
  • Consistent data snapshots (readers always see complete data versions)
  • Low-latency updates (write operations don't block readers)

Key Features

1. Optimized Memory Ordering

Uses precise std::memory_order semantics:

  • acquire before read operations
  • release after write operations
  • acq_rel for swap operations

2. Efficient Buffer Management

  • Fixed-size std::array storage (no dynamic allocation)
  • Atomic index swapping (no pointer indirection)
  • Cache-line aligned buffers (prevents false sharing)

3. Thread Safety Guarantees

  • Readers never block each other
  • Writer doesn't block ongoing reads
  • No data races or torn reads/writes

Performance Characteristics

Operation Latency (x86) Throughput (8-core)
Read ~3ns >100M ops/sec
Write ~15ns ~10M ops/sec

About

Modern cpp lock-free data structure for single-writer-multiple-reader scenarios

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published