Received: from eggs.gnu.org ([2001:4830:134:3::10]:34292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTb-0003zO-Go for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsYTZ-00082f-NM for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55980) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsYTZ-000826-GI for qemu-devel@nongnu.org; Fri, 07 Oct 2016 12:58:25 -0400 From: Paolo Bonzini Date: Fri, 7 Oct 2016 18:57:35 +0200 Message-Id: <1475859483-32234-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> References: <1475859483-32234-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 11/39] 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 Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= From: Alex Benn=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=C3=A9e Message-Id: <20160930213106.20186-3-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- 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) \ ({ \ --=20 2.7.4