当前位置:网站首页>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状态无修改的只读访问函数。
边栏推荐
- JVM内存模型和结构详解(五大模型图解)
- 有什么好的开源自动化测试框架可以推荐?
- An in-depth understanding of the implementation principle of Hybrid
- URLError: <urlopen error [Errno 11004] getaddrinfo failed>调用seaborn-data无法使用
- [SUCTF 2019]CheckIn
- 方舟开服务器Vmware虚拟机安装不上?
- What are some good open source automation testing frameworks to recommend?
- Detailed explanation of JVM memory model and structure (five model diagrams)
- IMX6ULL—Assembly LED Lights
- Jenkins使用pipeline部署服务到远程服务器
猜你喜欢

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

Wallys/QCA 9880/802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz advanced edition

loadrunner script -- parameterization

Volatile:JVM 我警告你,我的人你别乱动

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

软件设计的七大原则

从事软件测试一年,只会基础的功能测试,怎么进一步学习?

Flink on Yarn

低代码平台和专业开发人员——完美搭档?

100+开箱即用的AI工具箱;程序员150岁长寿指南;『地理空间数据科学』课程资料;Graphic数据可视化图表库;前沿论文 | ShowMeAI资讯日报
随机推荐
URLError: <urlopen error [Errno 11004] getaddrinfo failed>调用seaborn-data无法使用
How to choose a good SaaS knowledge base tool?
Volatile: JVM I warn you, my people don't move
International Soil Modeling Consortium-ISMC
传统数据中台又贵又复杂?何不试一试永久免费的下一代数据中台
kakka rebalance解决方案
MySQL数据指令
腾讯云2022年8月积分商城规则更新
最强分布式锁工具:Redisson
Logic unauthorized and horizontal and vertical unauthorized payment tampering, verification code bypass, interface
IMX6ULL—Assembly LED Lights
李乐园:iMetaLab Suite宏蛋白质组学数据分析与可视化(视频+PPT)
The principle implementation of handwritten flexible.js, I finally understand the multi-terminal adaptation of the mobile terminal
QoS - ROS2 principle 9 】 【 deadline, activity and life
以技术御风险,护航云原生 | 同创永益 X 博云举办产品联合发布会
【工业数字化大讲堂 第二十一期】企业数字化能碳AI管控平台,特邀技术中心总经理 王勇老师分享,8月11日(周四)下午4点
解决启动项目初始化报错required a bean of type ‘int‘ that could not be found.的问题
2022秋招面试宝典,啃完面试稳了
2022 全球 AI 模型周报
一口气拿下6个大厂offer,是什么水平