In RawKV, compare-and-swap (CAS) is an atomic instruction to achieve synchronization between multiple threads.
Performing CAS is an atomic equivalent of executing the following code:
Make sure that you have installed TiUP, jshell, downloaded tikv-client JAR files, and started a TiKV cluster according to TiKV in 5 Minutes.
Verify CAS
To verify whether CAS works, you can take the following steps.
Step 2: Run the code
The example output is as follows:
As in the example output, after calling compareAndSet
, the value CAS
is replaced by newValue
.
To guarantee the atomicity of CAS, write operations such as
put
ordelete
in atomic mode take more resources.