[英]Is there anything like Java's AtomicStampedReference in C++?
I am learning lock-free structure, and I noticed an ABA problem.我正在学习无锁结构,我注意到一个 ABA 问题。
I think Java's AtomicStampedReference
can solve this problem.我认为 Java 的AtomicStampedReference
可以解决这个问题。
So, is there anything similar in C++ that can solve this?那么,C++ 中有没有类似的东西可以解决这个问题?
There isn't a direct equivalent.没有直接的等价物。 You could implement it yourself, the source for AtomicStampedReference
is here: https://github.com/JetBrains/jdk8u_jdk/blob/master/src/share/classes/java/util/concurrent/atomic/AtomicStampedReference.java你可以自己实现它, AtomicStampedReference
的源代码在这里: https : //github.com/JetBrains/jdk8u_jdk/blob/master/src/share/classes/java/util/concurrent/atomic/AtomicStampedReference.java
You could probably implement this in c++ maybe making use of std::atomic<std::shared_ptr>
to implement the private volatile Pair<V> pair
.您可能可以在 C++ 中实现它,也许使用std::atomic<std::shared_ptr>
来实现private volatile Pair<V> pair
。
If you don't need the full functionality of AtomicStampedReference
you can probably use std::atomic<std::shared_ptr>
directly in your code.如果您不需要AtomicStampedReference
的全部功能,您可以直接在代码中使用std::atomic<std::shared_ptr>
。 If you don't have c++20 then you can use the previous stand-alone atomic shared_ptr
functions如果你没有 c++20 那么你可以使用以前的独立原子shared_ptr
函数
Maybe you should look at std::atomic
.也许你应该看看std::atomic
。 I have never heard of "AtomicStampedReference", but from just a cursory look, it seems to be an atomic reference.我从未听说过“AtomicStampedReference”,但粗略地看,它似乎是一个原子引用。 std::atomic
is for atomic variables. std::atomic
用于原子变量。 Hopefully this is what you're looking for.希望这就是你正在寻找的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.