Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

How it works...

In this recipe, we will learn how to use C++'s atomic data types. Atomic data types are limited to simple data types such as integers, and since these data types are extremely complicated to implement, the only operations that are supported are simple operations such as add, subtract, increment, and decrement.

Let's take a look at a simple example that not only demonstrates how to use an atomic data type in C++, but also demonstrates why atomic data types are so important:

#include <atomic>#include <thread>#include <iostream>int count{};std::atomic<int> atomic_count{};void foo(){    do {        count++;        atomic_count++;    }    while (atomic_count < 99999);}int main(void){    std::thread t1{foo};    std::thread t2{foo};    t1.join();    t2.join(); std::cout ...
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.
Start your free trial

You might also like

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content