【C/C++】标准库之 atomic

本文介绍了C/C++中的atomic类型,这是一种保证内存数据访问不会产生数据竞争并可用于不同线程间同步的类型。它通过atomic和atomic_flag类实现,并提供了与C风格的原子操作函数兼容的全套功能。示例中展示了如何使用atomic_int进行读写操作,确保在多线程环境中的安全性。
摘要由CSDN通过智能技术生成

Backto C/C++ Index


atomic 指的是原子操作, 一个一个来, 谁也别抢, 急也没用. 只要用于对内存数据的原子保护.

Atomic types are types that encapsulate a value whose access is guaranteed to not cause data races and can be used to synchronize memory accesses among different threads.

This header declares two C++ classes, atomic and atomic_flag, that implement all the features of atomic types in self-contained classes. The header also declares an entire set of C-style types and functions compatible with the atomic support in C.

// atomic::operator=/operator T example:
#include <iostream>       // std::cout
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值