std::atomic<bool>
This lesson gives an overview of std::atomic<bool> which is used from the perspective of concurrency in C++.
We'll cover the following...
Let’s start with the full specializations for bool: std::atomic<bool>
std::atomic<bool>
std::atomic<bool> has a lot more to offer than std::atomic_flag. It can explicitly be set to true or false.
atomicis notvolatileWhat does the keyword
volatilein C# and Java have in common with the keywordvolatilein C++? Nothing! It’s so easy in C++. That is the difference betweenvolatileandstd::atomic.
volatile: is for special objects, on which optimized read or write operations are not allowed
std::atomic: defines atomic variables, which are meant for a thread-safe reading and writing
It’s so easy, but the confusion starts exactly here. The keyword
volatilein Java and C# has the meaning ofstd::atomicin C++, i.e.volatilehas no multithreading semantic in C++.
volatileis typically used in embedded programming to denote objects which can change independently of the regular program flow. One example is an object which represents an external ...