29.7 Atomics
I would like to give some advice here in the form of light warnings for dealing with an area of C++. Here are the most important guidelines for dealing with atomic:
-
Do not use atomic unless you have to.
-
Check the success through profiling before and after. Too often, a brilliant “optimization” turns out to be counterproductive.
-
Stick to the default memory_order_seq_cst for the operation mode of atomic. The other variants only have more runtime benefits than implementation costs in the most extreme situations.
I recommend that you start with a variable protected by a mutex, gather experience, and then—maybe—experiment with atomic.
With that in mind, let me explain what you need atomic for.
You have seen that you can synchronize ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access