A hands-on C++ monorepo designed to practice systems programming fundamentals, including:
- custom memory allocation
- in-memory data structures
- hash tables (chaining + open addressing)
- caching & eviction
- RAII + smart pointers
- lock-free concurrency
- thread pools & work stealing
- modular CMake builds
- logging
- unit testing
This repository contains multiple realistic projects that build on each other — progressing from memory allocators → hash maps → KV stores → caching → smart pointers → concurrency.
| Module | Description |
|---|---|
common/ |
Shared utilities (logging) |
memory_pool/ |
Fixed-block allocator for efficient small allocations |
hash_map/ |
Custom separate-chaining HashMap (replaces std::unordered_map) |
kv_store_chaining/ |
KV store using chaining + memory_pool |
kv_store_linear/ |
KV store using open addressing + fixed-inline buffers (cache-friendly) |
lru_cache/ |
Modern LRU cache using hash_map + std::list |
in_memory_redis/ |
Redis-style store with TTL, prefix lookup, background sweeper |
smart_pointers/ |
Custom RAII pointers (UniquePtr, SharedPtr, WeakPtr) |
lock_free_queue/ |
MPMC lock-free queue using atomic CAS (Michael–Scott style) |
thread_pool/ |
Work-stealing thread pool with per-thread task queues & futures |
Each module:
- is standalone
- exports a library target
- has a demo executable
- has unit tests
- avoids dependencies except STL / gtest
common (logging utilities)
├─ memory_pool (allocators)
│ └─ kv_store_chaining
│ └─ (application layer)
│
├─ hash_map (chaining-based)
│ ├─ kv_store_chaining
│ └─ lru_cache
│ └─ in_memory_redis
│
├─ kv_store_linear (independent)
├─ smart_pointers (RAII utilities)
├─ lock_free_queue (concurrency)
└─ thread_pool (concurrency)
Dependency Rules:
common← base layer (no dependencies)- Foundation layer ←
commononly - Application layer ← Foundation + others as needed
- Concurrency (
lock_free_queue,thread_pool) ←commononly (no cross-dependencies)
cpp-systems-playground/
│
├── common/
├── memory_pool/
├── hash_map/
│
├── kv_store_chaining/
├── kv_store_linear/
│
├── lru_cache/
├── in_memory_redis/
│
├── smart_pointers/
├── lock_free_queue/
├── thread_pool/
│
└── build/
| Module | Collision Handling | Allocation | Value Storage | Strength |
|---|---|---|---|---|
| chaining | separate chaining | pool | dynamic | flexible & simple |
| linear probing | open addressing | contiguous | fixed inline | fast & cache-efficient |
| Module | Focus / Concept |
|---|---|
lock_free_queue |
atomic CAS, ABA avoidance, MPMC queues |
thread_pool |
work stealing + futures + per-thread queues |
Configure:
cmake -S . -B buildBuild everything:
cmake --build build -jSample specific targets:
cmake --build build --target lock_free_queue_demo
cmake --build build --target thread_pool_demo
cmake --build build --target in_memory_redis_demo./build/lock_free_queue/lock_free_queue_demo
./build/thread_pool/work_stealing_thread_pool_demoAlso available:
./build/hash_map/hash_map_demo
./build/lru_cache/lru_cache_demo
./build/smart_pointers/smart_pointers_demoRun all:
cd build
ctest --output-on-failureExamples:
./build/lock_free_queue/lock_free_queue_tests
./build/thread_pool/thread_pool_tests
./build/kv_store_linear/kv_store_linear_testsBy completing this repo, you’ll understand:
- hash maps (chaining + open addressing)
- memory pool allocators
- KV stores
- LRU caching
- lock-free MPMC queues
- thread pools & futures
- work-stealing schedulers
- condition variable wake/sleep
- atomic CAS operations
- RAII + ownership models
- templates + type traits
std::invoke_result_tstd::function,std::packaged_task- orphan avoidance & move semantics
Potential next modules:
- robin-hood hashing
- PMR-optimized structures
- persistent backed Redis (WAL)
- parallel sort / map-reduce
- Lock-free stack
- actor runtime on thread pool
- benchmark suite
Open to:
- performance improvements
- lock-free structures
- thread pool extensions
- bug reports & tests
- benchmark additions
- more allocator patterns
This is a playground — explore, break, optimize, and learn.
MIT — free to use and modify.