Fetch-And-Add
Explore the fetch-and-add instruction, a hardware primitive that atomically increments a value and returns the old one. Understand how it can be used to implement ticket locks to ensure fair thread scheduling and progress in concurrent programming. This lesson emphasizes writing concise, efficient synchronization code with real-world locking algorithms.
We'll cover the following...
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:
TIP: LESS CODE IS BETTER CODE (LAUER’S ...