Copy constructor for classes with atomic member

后端 未结 3 1992
清酒与你
清酒与你 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:46

    No, if you don't know how it will be used, you should use memory_order_seq_cst to be safe. If you use memory_order_relaxed, you could run into issues with instructions being reordered.

提交回复
热议问题