I am learning lock-free structure, and I noticed an ABA problem.
I think Java's AtomicStampedReference can solve this problem.
So, is there anything similar in C++ that can solve this?
I am learning lock-free structure, and I noticed an ABA problem.
I think Java's AtomicStampedReference can solve this problem.
So, is there anything similar in C++ that can solve this?
realestLink
On
Maybe you should look at std::atomic. I have never heard of "AtomicStampedReference", but from just a cursory look, it seems to be an atomic reference. std::atomic is for atomic variables. Hopefully this is what you're looking for.
Copyright © 2021 Jogjafile Inc.
There isn't a direct equivalent. You could implement it yourself, the source for
AtomicStampedReferenceis here: https://github.com/JetBrains/jdk8u_jdk/blob/master/src/share/classes/java/util/concurrent/atomic/AtomicStampedReference.javaYou could probably implement this in c++ maybe making use of
std::atomic<std::shared_ptr>to implement theprivate volatile Pair<V> pair.If you don't need the full functionality of
AtomicStampedReferenceyou can probably usestd::atomic<std::shared_ptr>directly in your code. If you don't have c++20 then you can use the previous stand-alone atomicshared_ptrfunctions