atomic Lock

If multiple threads modify the same memory location concurrently, processors do not guarantee any specific result.

Lock

Load Lock/Store Conditional (LL/SC)41 The LL/SC operations work as a pair where the special load instruction is used to start an transaction and the final store will only succeed if the location has not been modified in the meantime. The store oper- ation indicates success or failure, so the program can repeat its efforts if necessary.

1
int curval;
int newval;
do {
  curval = LL(var);
  newval = curval + addend;
} while (SC(var, newval));

#CAS

Compare-and-Swap (CAS) This is a ternary operation which writes a value provided as a parameter into an address (the second parameter) only if the cur- rent value is the same as the third parameter value;

1
2
3
4
5
6
int curval;
int newval;
do {
curval = var;
newval = curval + addend;
} while (CAS(&var, curval, newval));