Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What is a CAS operation?

Pragya Keshap answered on February 6, 2023 Popularity 2/10 Helpfulness 1/10

Contents


More Related Answers


What is a CAS operation?

0

CAS is also known a Compare-And-Swap operation.

In a CAS operation, the processor provides a separate instruction

that can update the value of a register only if the provided value is

equal to the current value.

CAS operation can be used as an alternate to synchronization.

Let say thread T1 can update a value by passing its current value

and the new value to be updated to the CAS operation. In case

another thread T2 has updated the current value of previous thread,

the previous thread T1’s current value is not equal to the current

value of T2. Hence the update operation fails.

In this case, thread T1 will read the current value again and try to

update it.

This is an example of optimistic locking

https://howtodoinjava.com/java/multi-threading/compare-and-swap-cas-algorithm/

Popularity 2/10 Helpfulness 1/10 Language whatever
Source: Grepper
Tags: cas whatever
Link to this answer
Share Copy Link
Contributed on Feb 06 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.