May 2017
Intermediate to advanced
590 pages
17h 18m
English
The following is a series of typical operations that use atomic types:
std::atomic<int> counter {0}; std::vector<std::thread> threads; for(int i = 0; i < 10; ++i) { threads.emplace_back([&counter](){ for(int i = 0; i < 10; ++i) ++counter; }); } for(auto & t : threads) t.join(); std::cout << counter << std::endl; // 100
std::atomic_flag lock = ATOMIC_FLAG_INIT; int counter = 0; std::vector<std::thread> threads; for(int i = 0; i < 10; ++i) { threads.emplace_back([&](){ while(lock.test_and_set(std::memory_order_acquire)); ...Read now
Unlock full access