January 2019
Intermediate to advanced
384 pages
11h 50m
English
We can avoid contention on a single resource if we simply duplicate it! The idea is that at some point we will than merge them back again if we need a unifying view.
An example of such a design is the ThreadCachedInt multithreaded counter class implemented in Facebook's Folly library. The idea is that every thread holds an integer counter locally and the global counter is updated periodically. It has two read methods: readFast() returns a potentially stale value with one load, and readFull() gives the exact value, but is much slower as it has to synchronize with all threads' local counters. So, we sacrifice the accuracy of the counter for fast updates in the threads, opting for eventual consistency. If you ...
Read now
Unlock full access