As discussed in #4583 this is a separate issue and needs its own thread. The original source for this consideration was a problem with static initialization of structs containing non-literal members (e.g., ones with volatile) in C++.
However, during the following discussion it was questioned if volatile is the right way to implement atomic integers. Here are some of our sources:
And some posts on Stack Overflow:
And related Wikipedia entires:
My current understanding is that memory barriers would be preferable to volatile. However, there are different barriers (compiler and hardware), which prevent memory reordering at different points. ARM architectures seem to have different reordering strategies than x86 ones.
Hardware memory barriers:
Two questions:
- Would an implementation without
volatile be preferable?
- What would it look like?
As discussed in #4583 this is a separate issue and needs its own thread. The original source for this consideration was a problem with static initialization of structs containing non-literal members (e.g., ones with volatile) in C++.
However, during the following discussion it was questioned if
volatileis the right way to implement atomic integers. Here are some of our sources:And some posts on Stack Overflow:
And related Wikipedia entires:
My current understanding is that memory barriers would be preferable to volatile. However, there are different barriers (compiler and hardware), which prevent memory reordering at different points. ARM architectures seem to have different reordering strategies than x86 ones.
Hardware memory barriers:
Two questions:
volatilebe preferable?