atomic compare_exchange_weak函数

compare_exchange_weak/compare_exchange_strong (是著名的CAS(compare and set))。
参数传入期待值与新值,通过比较当前值与期待值的情况进行区别改变。
a.compare_exchange_weak(b,c)其中a是当前值,b期望值,c新值
a==b时:函数返回真,并把c赋值给a
a!=b时:函数返回假,并把a复制给b

compare_exchange_weak比compare_exchange_strong的性能更高一些,常在循环中使用

 

posted @ 2023-01-12 19:18  angryCoder996  阅读(312)  评论(0编辑  收藏  举报