- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试将一些 Java 代码移植到 Windows C++,但对如何实现 AtomicLong.lazySet()
感到困惑。我能找到的唯一信息是谈论它的作用,而不是如何实现它,可用的源代码最终在 Sun 拥有的私有(private) native 库中 (sun.misc.Unsafe.class
)。
我目前只是为传递的参数设置了一个成员变量,但我不确定它是否正确。
class AtomicLong
{
public:
inline void LazySet(__int64 aValue)
{
// TODO: Is this correct?
iValue = aValue;
}
inline void Set(__int64 aValue)
{
::InterlockedExchange64(&iValue, aValue);
}
private:
__declspec(align(64)) volatile __int64 iValue;
};
我不能使用 boost。
编辑:我正在编译为 x64,但也许 32 位代码的解决方案会对其他人有所帮助。
我无法访问 C++11。
最佳答案
C++11 包含一个原子库,如果你会用它就很容易:
class AtomicLong
{
public:
inline void LazySet(int64_t aValue)
{
iValue.store(aValue, std::memory_order_relaxed);
}
inline void Set(int64_t aValue)
{
iValue.store(aValue);
}
private:
std::atomic<int64_t> iValue;
};
关于java - AtomicLong.lazySet 的 C++ 端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11888210/
文章“Atomic*.lazySet is a performance win for single writers”介绍了 lazySet 是一种弱 volatile 写入(从某种意义上说,它充当存
我正在尝试在 Haskell 中构建一个数据结构,它允许在有序的无限列表中进行高效查找。 如果这是 Java,我会做这样的事情: class LazySet { private Iterato
AtomicInteger 的 lazySet 和 set 方法有什么区别? documentation关于lazySet没什么可说的: Eventually sets to the given va
AtomicInteger的lazySet和set方法有什么区别? documentation lazySet 没什么好说的: Eventually sets to the given value.
我想了解 JAVA 中 volatile 变量的性能。 我看到 https://brooker.co.za/blog/2012/09/10/volatile.html当有作者参与时, volatile
我正在尝试将一些 Java 代码移植到 Windows C++,但对如何实现 AtomicLong.lazySet() 感到困惑。我能找到的唯一信息是谈论它的作用,而不是如何实现它,可用的源代码最终在
from django.conf import settings def my_view(self, request, *args, **kwargs): if 'LOCAL' in sett
在this video关于Disruptor ,一个并发框架,提到了 Java 的 Atomic* 类(例如 AtomicLong)的 lazySet 方法。根据documentation ,此方法“
在大多数 JMM 推理中使用的 AtomicXXX.lazySet(value) 方法是什么意思? javadocs 是纯粹的,Sun bug 6275329状态: The semantics are
我正在阅读 Hans 的一篇文章,他认为在 lazySet 或最终变量写入之前也需要 LoadStore。 他展示了一种我无法理解的特殊竞争条件。 http://www.hboehm.info/c++
我是一名优秀的程序员,十分优秀!