February 2018
Intermediate to advanced
298 pages
8h 22m
English
When I said updating a variable can be made atomic, it means that during the time a thread is accessing that memory, no other thread should be allowed to access it. This is only possible when you introduce a lock or a mutex (mutual exclusion) on the variable being accessed. This way, the other thread knows that the variable is in use and it should wait for the lock to be released.
This is how you make an operation atomic. But this sense of security also comes at a cost. Atomic locking is not an operation which will take negligible time, so it definitely involves some overhead.
Do it a billion times, and you're probably screwed (we'll see that soon in Fixing one billion count with atomics).
Read now
Unlock full access