Copy constructor for classes with atomic member

后端 未结 3 1984
清酒与你
清酒与你 2020-12-07 03:10

I have a class with an atomic member and i want to write a copy constructor:

struct Foo
{
    std::atomic mInt;

    Foo() {}
    Foo(const Foo&am         


        
3条回答
  •  春和景丽
    2020-12-07 03:40

    You only need a stronger memory ordering than memory_order_relaxed, if your copy operation is supposed to synchronize with other operations on a different thread.
    However, this is almost never the case, as a thread safe copy constructor will almost always require some external synchronization or an extra mutex anyway.

提交回复
热议问题