From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ou-0006Rc-DG for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq5Or-0006VG-0p for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:23 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Oq-0006Uu-Qg for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:20 -0400 Received: by mail-wm0-x22f.google.com with SMTP id b80so66254640wme.0 for ; Fri, 30 Sep 2016 14:31:20 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Fri, 30 Sep 2016 22:30:53 +0100 Message-Id: <20160930213106.20186-3-alex.bennee@linaro.org> In-Reply-To: <20160930213106.20186-1-alex.bennee@linaro.org> References: <20160930213106.20186-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v3 02/15] atomic.h: comment on use of atomic_read/set List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, pbonzini@redhat.com Cc: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, bobby.prani@gmail.com, nikunj@linux.vnet.ibm.com, mark.burton@greensocs.com, jan.kiszka@siemens.com, serge.fdrv@gmail.com, rth@twiddle.net, peter.maydell@linaro.org, claudio.fontana@huawei.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Add some notes on the use of the relaxed atomic access helpers and their importance for defined behaviour in C11's multi-threaded memory model. Signed-off-by: Alex Bennée --- include/qemu/atomic.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index c493f89..c4f6950 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -92,6 +92,12 @@ /* Weak atomic operations prevent the compiler moving other * loads/stores past the atomic operation load/store. However there is * no explicit memory barrier for the processor. + * + * The C11 memory model says that variables that are accessed from + * different threads should at least be done with __ATOMIC_RELAXED + * primitives or the result is undefined. Generally this has little to + * no effect on the generated code but not using the atomic primitives + * will get flagged by sanitizers as a violation. */ #define atomic_read(ptr) \ ({ \ -- 2.9.3