为什么atomic_flag默认构造函数会保留未指定状态? [英] Why atomic_flag default constructor leaves state unspecified?
本文介绍了为什么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屋!
查看全文