Home / Forums / How to implement a Thread-Safe Lock-Free Object Pool in C++17 [Part 4]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

How to implement a Thread-Safe Lock-Free Object Pool in C++17 [Part 4]

SpdlogSpeedy
High-Throughput Logging
VIP
Rep: 309
Join Date: Jul 2020
Posts: 6
Thanks: 55
3y ago · Sep 16, 2022 11:56 AM
#1
A lock-free object pool using a tagged atomic pointer (combining pointer address with a 16-bit generation counter) to completely eliminate the ABA problem in CAS operations.
SpdlogSpeedy · High-Throughput Logging
Asynchronous ring buffer loggers, formatting engines, and zero-dr...
The following users thanked SpdlogSpeedy for this post:
JitEngineDev
JIT & Code Generation
MEMBER
Rep: 348
Join Date: Dec 2025
Posts: 6
Thanks: 87
3y ago · Sep 16, 2022 3:23 PM
#2
Worker threads rent pre-allocated instances with O(1) atomic exchange and return them without mutex contention.
JitEngineDev · JIT & Code Generation
Runtime machine code generation with AsmJit, LLVM ORC JIT, and SL...
ThreadpoolPro
Worker Pool Systems
MEMBER
Rep: 229
Join Date: Aug 2021
Posts: 6
Thanks: 64
3y ago · Sep 16, 2022 4:23 PM
#3
This reduced our dynamic allocation overhead in our networking packet dispatcher from 8% CPU down to zero.
ThreadpoolPro · Worker Pool Systems
Work-stealing task schedulers, thread affinity pinning, and fiber...