如何在Java的Atomic *类中实现lazySet? [英] How is lazySet in Java's Atomic* classes implemented?

查看:264
本文介绍了如何在Java的Atomic *类中实现lazySet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此视频中,关于 Disruptor ,一个并发框架,Java的Atomic *类(例如AtomicLong)的lazySet方法被提及。根据文档,这个方法最终设置为给定的值。

In this video about Disruptor, a concurrency framework, the lazySet method of Java's Atomic* classes (e.g. AtomicLong) is mentioned. According to the documentation, this method "eventually sets to the given value".

有人知道底层机制是什么实现这一点(特别是在Windows上的x86,如果这是相关的)。它不能 InterlockedExchange(),因为这将设置值

Does anybody know what the underlying mechanism is to implement this (specifically on x86 on Windows, if that is relevant). It can't be InterlockedExchange(), because that would set the value and make sure cache lines are flushed before returning, if I'm not mistaken.

推荐答案

发现此实现的描述在< a href =http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6275329 =nofollow>错误6275329 :

语义是写保证不会与任何
以前的写入重新排序,但可以用后续操作重新排序
(或者等价地,可能不是对其他线程可见),直到
一些其他volatile写入或同步动作发生)。

The semantics are that the write is guaranteed not to be re-ordered with any previous write, but may be reordered with subsequent operations (or equivalently, might not be visible to other threads) until some other volatile write or synchronizing action occurs).

...

对于喜欢在公共多处理器上的
机器级障碍方面考虑这些操作的人,lazySet提供了一个
前存储 - 存储障碍(这是在当前平台上的非操作或非常便宜的
),但没有存储负载障碍(通常是易失性写入的
昂贵的部分)

For people who like to think of these operations in terms of machine-level barriers on common multiprocessors, lazySet provides a preceeding store-store barrier (which is either a no-op or very cheap on current platforms), but no store-load barrier (which is usually the expensive part of a volatile-write)

这篇关于如何在Java的Atomic *类中实现lazySet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆