When using std::atomic_flag
, one has to be careful to always explicitely initialize it using ATOMIC_FLAG_INIT
, which is error-prone. However there is a default constructor... So, is there an objective reason behind having a default constructor leaving the flag in an unspecifiate state ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With