July 2018
Intermediate to advanced
266 pages
7h 11m
English
Atomic operations are those that have non-interfered access to the data they use. In single-thread applications, all the operations will be atomic, because the execution of all the code will be sequential – and there can't be interference if only one thread is running.
Atomicity is wanted when the state of an object can be modified concurrently, and it needs to be guaranteed that the modification of that state will not overlap. If the modification can overlap, that means that data loss may occur due to, for example, one coroutine overriding a modification that another coroutine was doing. Let's see it in action:
var counter = 0fun main(args: Array<String>) = runBlocking { val workerA = asyncIncrement(2000) val workerB ...Read now
Unlock full access