A C++ concurrency learning repository with implementations of various synchronization primitives and concurrent data structures.
awesome-concurrency/
├── src/
│ ├── os/
│ │ └── futex/ # Linux futex (fast userspace mutex) system calls
│ ├── thread/
│ │ ├── sync/ # Synchronization primitives (spinlocks, mutexes, etc.)
│ │ └── util/ # Utility functions (spin wait hints, etc.)
│ └── common/
│ └── common/
│ └── containers/ # Concurrent data structures
├── examples/
│ └── sync/ # Examples demonstrating synchronization primitives
├── tests/
│ ├── sync/ # Synchronization primitive tests
│ └── containers/ # Concurrent data structure tests
└── .vscode/ # VS Code tasks and shortcuts
- CMake 3.14 or higher
- C++23 compatible compiler (GCC 12+, Clang 15+)
- pthread support
- clang-format (optional, for code formatting)
# Configure
cmake -B build -S .
# Build
cmake --build build
# Run tests
cmake --build build --target run-tests
# Format code
cmake --build build --target format- Futex - Linux futex (fast userspace mutex) wrapper for efficient kernel-level blocking
See src/thread/sync/ for detailed documentation.
- Three-State Mutex - Efficient mutex with fast-path (no syscall) lock/unlock and futex-based blocking
- MCS Spinlock - Scalable queue-based spinlock with FIFO ordering and minimal cache traffic
- Ticket Lock - Simple fair spinlock using ticket-based FIFO ordering
- TTAS Spinlock - Test-and-Test-and-Set spinlock with reduced cache coherence traffic
See src/common/common/containers/ for detailed documentation.
- RingBuffer - Lock-free SPSC ring buffer with atomic operations
- FastRingBuffer - Cache-optimized SPSC ring buffer with local index caching
- SpinLoopHint - Platform-specific CPU hints for busy-waiting
# Run all tests with CTest
cd build && ctest --output-on-failure
# Run specific test suite
./build/tests/sync/mcs_test
# Run with gtest filters
./build/tests/sync/mcs_test --gtest_filter=MCSSpinlockTest.MutualExclusion# Run MCS spinlock example
./build/examples/sync/mcs_exampleThis is an educational project. Feel free to use and modify as needed for learning purposes.