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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

How to implement a Thread-Safe Lock-Free Object Pool in C++17

LockFreeLarry
Concurrent Systems
MEMBER
Rep: 106
Join Date: Sep 2022
Posts: 6
Thanks: 45
3y ago · Sep 25, 2022 4:56 PM
#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.
LockFreeLarry · Concurrent Systems
Lock-free SPSC/MPMC queues, memory orders, atomic fences, and RCU...
The following users thanked LockFreeLarry for this post:
AllocMaster
Memory Arena Specialist
MEMBER
Rep: 80
Join Date: Feb 2021
Posts: 6
Thanks: 38
3y ago · Sep 25, 2022 6:36 PM
#2
Worker threads rent pre-allocated instances with O(1) atomic exchange and return them without mutex contention.
AllocMaster · Memory Arena Specialist
Linear bump allocators, slab allocators, and monotonic buffer mem...
CpuProfiler
Performance Engineering
MEMBER
Rep: 415
Join Date: Oct 2023
Posts: 6
Thanks: 61
3y ago · Sep 25, 2022 11:36 PM
#3
This reduced our dynamic allocation overhead in our networking packet dispatcher from 8% CPU down to zero.
CpuProfiler · Performance Engineering
Hardware performance counters, instruction retirement analysis, a...