Thread-safe lock-free array

后端 未结 3 1900
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 04:01

I have a C++ library, which supposed to do some computations on multiple threads. I made independent threads code (i.e. there are no shared variables between them), except f

3条回答
  •  抹茶落季
    2020-12-19 04:25

    You're trying to copy a non-copyable type: the AtomicUInt64 constructor takes an atomic by value.

    If you need it to be initialisable from atomic, then it should take the argument by (const) reference. However, in your case, it doesn't look like you need to initialise from atomic at all; why not initialise from uint64_t instead?

    Also a couple of minor points:

    • The copy constructor and assignment operator should take their values by const reference, to allow temporaries to be copied.

    • Allocating the vector with new is a rather odd thing to do; you're just adding an extra level of indirection with no benefit.

    • Make sure you never resize the array while other threads might be accessing it.

提交回复
热议问题