atomic increment with busy waiting
int atomic_increment(int *t) {
do {
int temp = *t;
} while (!compare_and_swap(t, temp, temp+1)); // busy wait
return temp+1;
}
Note we can’t do this:
int atomic_increment(int* t) {
while (!compare_and_swap(t, *t, temp+1));
return *t;
}