当前位置:网站首页>std::atomic_flag的test_and_set函数理解
std::atomic_flag的test_and_set函数理解
2022-08-09 17:24:00 【hellozhengyuan】
std::atomic_flag test_and_set函数理解
std::atomic_flag的test_and_set函数原型如下:
bool test_and_set(std::memory_order order = std::memory_order_seq_cst) volatile noexcept; (1) (since C++11)
bool test_and_set(std::memory_order order = std::memory_order_seq_cst) noexcept; (2) (since C++11)Atomically changes the state of a std::atomic_flag to set (true) and returns the value it held before.
atomic_flag只能有3个状态:
- 未设置(定义时未初始化,在c++20以后在定义时自动初始化为false,即在c++20以后此状态不再存在)
- 清除(false)
- 设置(true)
test_and_set函数的理解
此函数有两种语义:
- 1. test表示先测试(读取当前atomic_flag的值)并返回个这结果值;
- 2. set表示将atomic_flag状态设置为ture。
可以看出,test_and_set函数的返回值与set的结果没有关系,返回值只表示调用test_and_set函数前的atomic_flag当前的状态。调用此函数后atomic_flag状态一定为true。
可以看出atomic_flag原子变量的操作十分的有限。直到c++20以后才新增test()函数,对atomic_flag状态无修改的只读访问函数。
边栏推荐
- 释放数据价值的真正法宝,数据要素市场化开发迫在眉睫
- .NET 6学习笔记(4)——解决VS2022中Nullable警告
- ASP.NET Core依赖注入之旅:针对服务注册的验证
- Discuz! Forum program installation + template configuration tutorial
- win10 uwp 改变鼠标
- JVM内存模型和结构详解(五大模型图解)
- Wallys/QCA 9880/802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz advanced edition
- 怎样选择一个好的SaaS知识库工具?
- approach和method的区别
- About the common Hook encapsulation of DOM (2)
猜你喜欢

艺术与科技的狂欢,云端XR支撑阿那亚2022砂之盒沉浸艺术季

What are some good open source automation testing frameworks to recommend?

秋招面试大厂总被刷下来,你这样做保准你事半功倍!

JSDN blog system

uniapp中使用网页录音并上传声音文件(发语音)——js-audio-recorder的使用【伸手党福利】

ARM 汇编基础

十七、一起学习Lua 错误处理

How to play with container local storage through open-local? | Dragon Lizard Technology

测试开发是什么,为什么现在这么吃香?

ASP.NET Core依赖注入之旅:针对服务注册的验证
随机推荐
ref的使用
Entry node of ring in leetcode/linked list
[SUCTF 2019]CheckIn
论文解读:Deep-4MCW2V:基于序列的预测指标,以鉴定大肠杆菌中的N4-甲基环胞嘧啶位点
The most complete architect knowledge map in history
One-key login principle of local number
uniapp 实现底部导航栏tabbar
d中简单禁止垃集
win10 uwp 获取指定的文件 AQS
虚拟修补:您需要知道的一切
win10 uwp 改变鼠标
动态RDLC报表(五)
JSDN博客系统
动态RDLC报表(四)
[Pycharm easy to use function]
说了半天跨平台,今儿咱就来跨跨!(完结篇)——Kubenetes上手实践
Experience far more than Hue, this is the favorite SQL tool for technicians
线性代数学习笔记
Discuz! Forum program installation + template configuration tutorial
win10 uwp 无法附加到CoreCLR