...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::histogram::accumulators::thread_safe — Thread-safe adaptor for builtin integral and floating point numbers.
// In header: <boost/histogram/accumulators/thread_safe.hpp> template<typename T> class thread_safe : public std::atomic< T > { public: // types typedef T value_type; typedef std::atomic< T > super_t; // construct/copy/destruct thread_safe() noexcept; thread_safe(const thread_safe &) noexcept; thread_safe(value_type); thread_safe & operator=(const thread_safe &) noexcept; thread_safe & operator=(value_type); // public member functions thread_safe & operator+=(const thread_safe &); thread_safe & operator+=(value_type); thread_safe & operator++(); template<typename Archive> void serialize(Archive &, unsigned); };
This adaptor uses std::atomic to make concurrent increments and additions safe for the stored value.
On common computing platforms, the adapted integer has the same size and alignment as underlying type. The atomicity is implemented with a special CPU instruction. On exotic platforms the size of the adapted number may be larger and/or the type may have different alignment, which means it cannot be tightly packed into arrays.
thread_safe
public
construct/copy/destructthread_safe() noexcept;
thread_safe(const thread_safe & o) noexcept;
thread_safe(value_type arg);
thread_safe & operator=(const thread_safe & o) noexcept;
thread_safe & operator=(value_type arg);
thread_safe
public member functionsthread_safe & operator+=(const thread_safe & arg);
thread_safe & operator+=(value_type arg);
thread_safe & operator++();
template<typename Archive> void serialize(Archive & ar, unsigned);