January 2019
Intermediate to advanced
384 pages
11h 50m
English
This is advice which will often be heard, but is it really a cure-all? There are stories to be heard about dramatic performance improvements when using lock-free algorithms! Let's first explain what lock-free techniques are and then analyze their performance implications.
The simplest example of a lock-free construct is a spinning lock: we are using a compare and swap (CAS) atomic processor instruction and trying to set an integer to some value. The CAS instruction will return the previous value of the integer and, if it was the same value we are trying to set, we know that the other thread already set the value and thus acquired it. In that case, we simply spin:
QAtomicInt val = 0;// try to acquire
Read now
Unlock full access