Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • yeah from what I read compareAndSet is atomic as well. Also all I am asking is when do you ever use compareAndSet? What are the typical use cases ? Commented Jun 9, 2016 at 3:55
  • so compareAndSet is not atomic? Commented Jun 9, 2016 at 4:01
  • 2
    yes it is atomic that is what i explained (how it is achieved by the CAS machine instruction ), correct? Commented Jun 9, 2016 at 4:02
  • 3
    There's another use case for CAS that's simpler and probably even more common: incrementing an int. If you look at the code for incrementAndGet, you'll see it internally uses a CAS loop. Commented Jun 9, 2016 at 4:37
  • Apart from visibility and atomicity, another key part is ordering. So how loads/stores are ordered in the global memory order with respect to other loads/stores. Commented Oct 23, 2021 at 5:04