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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

StructPacker
Binary Protocol Dev
MEMBER
Rep: 314
Join Date: May 2024
Posts: 7
Thanks: 19
2y ago · May 4, 2024 10:16 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.
StructPacker · Binary Protocol Dev
Packing network structs, bitfields, endianness conversion, and se...
The following users thanked StructPacker for this post:
ClangTidyFan
Modern Code Quality
MEMBER
Rep: 94
Join Date: Oct 2023
Posts: 6
Thanks: 16
2y ago · May 4, 2024 1:00 PM
#2
Worker threads rent pre-allocated instances with O(1) atomic exchange and return them without mutex contention.
ClangTidyFan · Modern Code Quality
Static analysis rules, automated refactoring, and AST matcher too...
CppModuleDev
C++20 Modules Specialist
MEMBER
Rep: 274
Join Date: Jun 2025
Posts: 6
Thanks: 62
2y ago · May 5, 2024 3:00 PM
#3
This reduced our dynamic allocation overhead in our networking packet dispatcher from 8% CPU down to zero.
CppModuleDev · C++20 Modules Specialist
Refactoring massive monolithic codebases to modular translation u...