如何在 std::atomic 上运行compare_exchange_weak<bool>?
How to run compare_exchange_weak on an std::atomic<bool>?
我试过运行
std::atomic<bool> set(false);
然后在稍后的一个函数中,我尝试使用:
Process::signalsDone.compare_exchange_weak(false, true, std::memory_order_release, std::memory_order_relaxed);
为什么在编译时会出现错误消息?
error C2664: 'bool std::atomic<bool>::compare_exchange_weak(_Ty &,const _Ty,const std::memory_order,const std::memory_order) noexcept': cannot convert argument 1 from 'bool' to '_Ty &'
with
[
_Ty=bool
]
C:Program Files (x86)Microsoft Visual Studio2019ProfessionalVCToolsMSVC14.27.29110includeatomic(1636): note: see declaration of 'std::atomic<bool>::compare_exchange_weak'
compare_exchange_weak
的第一个参数是T&
。
不能将像false
这样的文字绑定到T&
;你从来没能做到这一点。
相反,创建一个类型为bool
的变量,该变量可以通过引用传递给函数。如果比较失败,变量的值将更改为atomic_bool
的实际值。
相关文章:
- EASTL矢量<向量<int>>连续的
- 为什么"weak.lock()"返回"nullptr" "auto weak=std::make_shared<int>(42);"的定义?
- 为什么使用模板生成的函数具有"weak"符号类型?
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 为什么原始指针没有"weak pointer"?还是有?
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- 错误c++visual studio c2227左侧'->;Init';必须指向类/结构/联合/泛型类型
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- ``这个''不能用this-&gt;指针变量
- 如何加入向量&lt; int&gt;到C 中的单个INT
- 是std :: set&lt; std :: future&gt;不可能存在