[riot-notifications] [RIOT-OS/RIOT] sys: Added simple memory barrier API (#11438)
notifications at github.com
Wed Apr 24 17:09:08 CEST 2019
maribu commented on this pull request.
> + * @brief Memory Barriers
+ * # FAQ
+ * ## What are Memory Barriers
+ * Memory barriers suppress specific kinds optimization performed by the
+ * compiler or (in case of out-of-order CPUs) CPUs, depending on the barrier.
+ * This will most likely result in slower program execution and, thus, is in
+ * general unwanted. However, under specific circumstances, optimization can
+ * prevent correct execution.
+ * ## Why can't I use `volatile` instead
+ * Memory accesses to `volatile` can be viewed as an alternative to
+ * @ref compiler_barrier, but only in regard to other accesses to `volatile`
+ * variables. (Some compilers do not reorder memory accesses to non-`volatile`s
+ * across accesses to `volatile`s as well, but not all compilers do so.)
+ * Resorting to mark all variables as `volatile` to enforce the correct order
At least in practical code it is observed to perform better to use barriers (see the Linux reference regarding volatile at the bottom). We need to keep in mind that the typical use case is something like:
It is very unlikely that memory considered to require being put behind a barrier is accessed unprotected just after the barrier.
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...
More information about the notifications