Skip to content

Instantly share code, notes, and snippets.

View Jasdent's full-sized avatar

zhuokuny Jasdent

  • Guangzhou
View GitHub Profile
@glampert
glampert / atomic_slist_128bits_cas.cpp
Created March 20, 2017 17:52
Atomic/lockless linked list using 128-bits Compare And Swap to solve the A-B-A problem.
// --------------------------------------------------------------------------------------
// Atomic singly-linked intrusive list using 128-bits Compare And Swap (AKA: DCAS).
// Keeps a version counter with the list head to prevent the A-B-A problem.
//
// Based on the implementation found in moodycamel.com:
// http://moodycamel.com/blog/2014/solving-the-aba-problem-for-lock-free-free-lists
//
// My implementation uses raw GCC/Clang atomics intrinsics. While in theory
// std::atomic of a struct of exactly 16 bytes and properly aligned could