July 2018
Intermediate to advanced
266 pages
7h 11m
English
During this chapter, we have covered how to write our own atomic blocks of code, but there's yet another topic that we need to mention regarding atomicity: atomic data structures. These are data structures that offer atomic operations out of the box.
For example, using an atomic integer looks like the following:
val counter = AtomicInteger()counter.incrementAndGet()
Because the implementation of incrementAndGet() is atomic, we can use it easily to implement a thread-safe counter:
var counter = AtomicInteger()fun asyncIncrement(by: Int) = ...
Read now
Unlock full access