| Home | Libraries | People | FAQ | More

## Class template thread_safe

boost::histogram::accumulators::thread_safe — Thread-safe adaptor for builtin integral numbers.

## Synopsis

    // 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);
    };

## Description

This adaptor uses atomic operations 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.

### Template Parameters

1.     typename T

   type to adapt, must be an integral type.

### `thread_safe` public construct/copy/destruct

1.     thread_safe() noexcept;

2.     thread_safe(const thread_safe & o) noexcept;

3.     thread_safe(value_type arg);

4.     thread_safe & operator=(const thread_safe & o) noexcept;

5.     thread_safe & operator=(value_type arg);

### `thread_safe` public member functions

1.     thread_safe & operator+=(const thread_safe & arg);

2.     thread_safe & operator+=(value_type arg);

3.     thread_safe & operator++();

4.     template<typename Archive> void serialize(Archive & ar, unsigned);