January 2020
Intermediate to advanced
640 pages
16h 56m
English
In the Chapter08/bspgraph/aggregator package, you can find two concurrent-safe accumulator implementations that are designed to work with int64 and float64 values and can also double as distributed counters.
Instead of using a mutex to guarantee concurrent access, both accumulators are implemented using compare and swap instructions. The int64-based version is pretty straightforward and can easily be implemented with the help of the functions provided by the sync/atomic package. The float64-based version, which we will be dissecting here, is more challenging (and fun!) since the sync/atomic package offers no support for dealing with floating-point values. To work around this limitation, ...