Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why atomic_flag default constructor leaves state unspecified?

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 ?

like image 808
Synxis Avatar asked Feb 22 '16 10:02

Synxis


1 Answers

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.

like image 105
VLL Avatar answered Nov 17 '22 20:11

VLL