虚假唤醒、atomic

1.虚假唤醒 : wait 函数中要有第二个参数(lambda表达式),并且这个 lambda表达式中要正确判断要处理的公共数据是否存在。

2.atomic 

std::atomic<int> atm;
//std::atomic<int> atm2=atm;
//std::atomic<int> atm3(atm);
//atm2 = atm;

1.atomic 禁止了拷贝构造函数和赋值操作符函数。

2.load() :以原子方式读 atomic对象的值。

std::atomic<int> atm;
std::atomic<int> atm2(atm.load());
auto atm3(atm.load());

3.store() :以原子的房子写入内容

std::atomic<int> atm;
    std::atomic<int> atm2(atm.load());
    auto atm3(atm.load());

    atm2.store(12);

posted @ 2022-12-15 21:46  repinkply  阅读(36)  评论(0)    收藏  举报