为什么atomic_flag默认构造函数会保留未指定状态? [英] Why atomic_flag default constructor leaves state unspecified?

查看:84
本文介绍了为什么atomic_flag默认构造函数会保留未指定状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 std::atomic_flag 时,请务必始终保持明确使用容易出错的 ATOMIC_FLAG_INIT 对其进行初始化.但是,有一个默认的构造函数...因此,是否有一个客观的原因使默认的构造函数使标志保持未指定状态?

推荐答案

dyp 在评论中发布)描述了此决定是因为在某些体系结构上,零初始化atomic_flag对应于置位状态,而在某些体系结构上,其对应于清零状态.因此,已定义未使用ATOMIC_FLAG_INIT显式初始化的atomic_flag最初处于不确定状态.

This link (posted by dyp in comments), describes that this decision was made because on some architectures a zero-initialized atomic_flag would correspond to a set state, and on some it would correspond to a cleared state. Because of this, it was defined that an atomic_flag that is not explicitly initialized with ATOMIC_FLAG_INIT is initially in an indeterminate state.

这篇关于为什么atomic_flag默认构造函数会保留未指定状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆