C++ std::atomic vs. Boost atomic

I’m not an expert or anything, but here’s what I know:

  1. std::atomic simply says that calling load and store (and a few other operations) concurrently is well-defined. An atomic operation is indivisible – nothing can happen ‘in-between’.
  2. I assume std::atomic is based off of boost::atomic. If you can, use std, otherwise use boost.
  3. They are both portable, with the std being completely so, however your compiler will need to support C++11
  4. Likely std::atomic_bool. You should not need to use volatile.

Also, I believe load/store differs from operator=/operator T only load/store are atomic.

Nevermind. I checked the standard and it appears that the operators are defined in terms of load/store/etc, however they may return different things.

Further reading:

  • http://en.cppreference.com/w/cpp/atomic/atomic
  • C++11 Standard
  • C++ Concurrency in Action

Leave a Comment