Relative Content

Tag Archive for c++caslock-free

Unexpected Behavior with compare_exchange_strong in Single Producer Multi Consumer Queue Implementation

I’m working on a single-producer, multi-consumer lock-free queue implementation in C++. The code is based on examples from the book Concurrency in Action by Anthony Williams. However, I have encountered an issue with compare_exchange_strong that I can’t quite explain. Even with only one push thread, compare_exchange_strong occasionally fails in a way that suggests it was interrupted or otherwise preempted. Here is a simplified version of my code: