Atomic Smart Pointers
Get introduced to 'std::shared_ptr' template.
We'll cover the following...
A std::shared_ptr consists of a control block and its resource. The control block is thread-safe, but access to the resource is not. This means modifying the reference counter is an atomic operation and you have the guarantee that the resource is deleted exactly once. These are the guarantees std::shared_ptr
gives you.
🔑 The importance of being thread-safe
I want to take a short detour to emphasize how important it is that the
std::shared_ptr
has well-defined multithreading semantics. At first glance, the use of astd::shared_ptr
does not appear to be a sensible choice for multithreaded ...