1

I recently came to know about CAS - Compare and Set and I tried to know more about it. I checked online in quest to know more and came across this link.

How is it possible that without locking , using CAS threads can get / update values.

For example, in multicore processors they keep values in their own cache (and that is why we use volatile when we want threads to read latest values). So, even if, there is CAS, won't threads trying to do this operation be reading from their own cache?

Are these types of operations to be supported by Hardware? Any inputs, as a novice how to get familiar with this?

CuriousMind
  • 8,301
  • 22
  • 65
  • 134
  • 1
    See [here](https://stackoverflow.com/questions/4183202/java-compare-and-swap-semantics-and-performance). Those operations add memory barriers +/- equivalent to `volatile`. – Sotirios Delimanolis May 24 '20 at 21:51
  • @SotiriosDelimanolis: Thanks for sharing the link. I am in incipient stage of understanding. Assuming same code to executed by two different threads, how does it work? At least any one of the thread has to "wait" for a while? How is it possible that without any synchronization, they have recent updates? Could you elaborate a bit? – CuriousMind May 24 '20 at 22:01

0 Answers0