Fetch-And-Add
Let's look at one last hardware primitive for building locks, the fetch-and-add instruction.
We'll cover the following...
One final hardware primitive is the fetch-and-add instruction, which atomically increments a value while returning the old value at a particular address. The C pseudocode for the fetch-and-add instruction looks like this:
int FetchAndAdd(int *ptr) {int old = *ptr;*ptr = old + 1;return old;}
TIP: LESS CODE IS BETTER CODE (LAUER’S LAW)
Programmers tend to brag about ...
Ask