Grokking Concurrency in Go
0% completed
Compare and Swap
How can eight goroutines keep track of the slowest response they have seen, without a mutex? Each goroutine measures latencies, and a shared value must always hold the largest one so far.
The tools from Atomic Operations do not solve this on their own. Add changes the value by a fixed amount, but a maximum needs a comparison first. A Load followed by a Store makes the comparison possible, yet another goroutine can store a larger value between the two calls, and the Store then overwrites it with a smaller one
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%