Skip to Content
Hands-On Software Engineering with Golang
book

Hands-On Software Engineering with Golang

by Achilleas Anagnostopoulos
January 2020
Intermediate to advanced
640 pages
16h 56m
English
Packt Publishing
Content preview from Hands-On Software Engineering with Golang

Implementing a lock-free accumulator for float64 values

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, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Software Architecture with Golang

Hands-On Software Architecture with Golang

Jyotiswarup Raiturkar

Publisher Resources

ISBN: 9781838554491Supplemental Content