-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Volatile might not be the best (or even right) implementation for atomics #4700
Comments
Worth mentioning is that our target platforms, tiny MCUs, are usually without CPU cache, so hardware barriers may not be necessary (or even available) on all platforms. Added link to ARM document about Cortex-M memory barriers |
I have been thinking of this issue for some time now, and I agree that the current implementation is not optimal.
To solve the maintenance problem, we could use the upstream solutions from the toolchain developers:
|
Using a maintained implementation sounds like the right thing to do, no need to do this once more--especially when considering how complicated the topic is. The docs say that the compiler gives a warning if For our implementation this would mean to use The C11 atomics seem complicated to use. None the less, if we'd move to C11 I think going with the standard is the right thing to do. |
#5688 fixes this by removing atomic.h and replacing it with compiler intrinsics and a helper library for when the hardware is missing support for lockless atomic operations. |
@gebart So ... this issue can be closed, right? |
Yes, I forgot to close after #5688 was merged. |
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:
volatile
be preferable?The text was updated successfully, but these errors were encountered: