Fetch-and-add Primitive and Ticket Lock
What does the primitive do? Increase an integer value by 1 Return the original value It’s a hardware primitive, hence atomic. It can be used to implement a ticket lock. How it works Say t0, t1, t2 both arrives at line 12 Since FetchAndAdd() is atomic, the changes made by threads are serialized. Let’s assume …