How to use std::atomic<>

后端 未结 4 1872
南笙
南笙 2021-01-30 09:25

I have a class that I want to use in different threads and I think I may be able to use std::atomic this way:

class A
{
    int x;

public:
    A()
         


        
4条回答
  •  感动是毒
    2021-01-30 09:50

    Declare the class member x as atomic, then you don't have to declare the object as atomic:

    class A
    {  
       std::atomic x;
    };
    

提交回复
热议问题