How is lazySet in Java's Atomic* classes implemented?

后端 未结 2 1607
别跟我提以往
别跟我提以往 2021-02-09 03:04

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

2条回答
  •  悲哀的现实
    2021-02-09 03:16

    Found this description of the implementation in Bug 6275329:

    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).

    ...

    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)

提交回复
热议问题