0

I am trying to set up an atomic vector, like

struct Vector
{
    double data[3];
};

and i wish it work atomicly in TBB. So I used

tbb::atomic<Vector> atomic_vec;

However, it failed to work, as the compiler stating tbb::internal::atomic_impl<T>::my_storage has incomplete type. I inspected tbb/atomic.h and found the relevant tbb::internal::aligned_storage<Vector, sizeof(Vector)=24ul> not specialized. Is there a way of avoiding this?

xis
  • 24,330
  • 9
  • 43
  • 59

1 Answers1

1

tbb::atomic can be instantiated with types no greater than 64 bit as tbb::atomic designed to use "non blocking" hardware primitives. This is a limitation of vast majority of hardware TBB is intended to run on.

  • From the source code, it is recognized that the chip has to support atomic instructions like "compare and swap". This makes TBB limited to specified types. C++11 std::atomic does not have such limitation – xis Jul 15 '13 at 16:56
  • When designing the tbb::atomic interface, we had a choice between supporting only operations that had reasonably widespread hardware support, or generalizing to operations that required extensive software support. We decided to stay close to the hardware. Note that on almost all current platforms, a C++11 std::atomic will be implemented with a hidden lock, hence negating much of the benefit of atomic operations anyway. – Arch D. Robison Jul 18 '13 at 14:48