Skip to content

add lock-free stack (Treiber)#1

Open
AneesPatel wants to merge 1 commit into
mainfrom
feat/lock-free-stack
Open

add lock-free stack (Treiber)#1
AneesPatel wants to merge 1 commit into
mainfrom
feat/lock-free-stack

Conversation

@AneesPatel

Copy link
Copy Markdown
Owner

What

Adds a lock-free stack using the Treiber algorithm. Push and pop both use compare_exchange_weak on the head pointer - no mutexes, no locks.

Notes

  • ABA problem is documented in a comment. Not a concern for current use cases but would need tagged pointers or hazard pointers for production.
  • Destructor drains the stack to free heap-allocated nodes.
  • Stress test: 4 producers push 10k items each, 4 consumers race to drain, verify total count.

Files

  • include/LockFreeStack.h
  • tests/test_lockfreestack.cpp
  • CMakeLists.txt - add test executable

CAS-based lock-free stack. Has the ABA problem noted in a comment,
good enough for now. Added stress test with 4 producers / 4 consumers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant