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:

Get hands-on with 1200+ tech skills courses.