1. 5
  1. 3

    I have some bad news for you.

    First of all, the code

    _lock.lock();
    if (head[nb] == NULL)
        head[nb] = new atomic_ring_element<Z>(zero);
    _lock.unlock();
    

    is not exception-safe (though this can be easily fixed).

    More problematic is that C++‘s std::atomic<T> isn’t necessarily lock-free:

    1. 2

      It’s not really news that atomics aren’t necessarily lock free; it just means there are some restrictions on what types it makes sense to use them for. Scalars that fit into a CPU word and pointers, basically. By using pointers you can manage larger more complex objects. (Though I don’t believe atomic unique_ptrs are lock-free, so you need to do some manual memory management.)