Search code examples
templatesatomictbb

How to make TBB accept non-standard type of T for tbb::atomic<T>


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?


Solution

  • 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.