[riot-notifications] [RIOT-OS/RIOT] sys: Added simple memory barrier API (#11438)

Marian Buschsieweke notifications at github.com
Fri Apr 26 11:36:41 CEST 2019

@kaspar030: The C standard is sadly not that clear on whether memory accesses that are not marked as `volatile` can be moved across `volatile` memory accesses. Citing from [John Regehr - Nine ways to break your systems code using volatile](https://blog.regehr.org/archives/28):

> One school of thought is that compilers may not move accesses to global variables around accesses to volatile variables.  There seems to be a consistent reading of the standard that backs this up.  The problem with this reading is that important compilers are based on a different interpretation, which says that accesses to non-volatile objects can be arbitrarily moved around volatile accesses.

So while GCC does tread accesses to `volatile` memory as a compiler barrier (or at least both the version you are running and the version I am using), there is no way to rely on that.

But we also need to keep in mind that this actually doesn't matter: Even if every compiler supported by RIOT does tread accesses to `volatile` as a compiler barrier, we still need to keep in mind that hardware memory barriers might also be needed. Thus, using `volatile` as memory barrier is not possible.

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190426/1c96d680/attachment.html>

More information about the notifications mailing list