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

Marian Buschsieweke 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:

``` C
barrier()
access_to_critical_data()
barrier()
```

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:
https://github.com/RIOT-OS/RIOT/pull/11438#discussion_r278175543
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190424/523daf72/attachment.html>


More information about the notifications mailing list