From a71ca3dfbd32faf351ff68bcc26a4d5abd9b06d7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 26 Jan 2022 16:53:50 -0500 Subject: runtime, sync, sync/atomic: document happens-before guarantees A few of these are copied from the memory model doc. Many are entirely new, following discussion on #47141. See https://research.swtch.com/gomm for background. The rule we are establishing is that each type that is meant to help synchronize a Go program should document its happens-before guarantees. For #50859. Change-Id: I947c40639b263abe67499fa74f68711a97873a39 Reviewed-on: https://go-review.googlesource.com/c/go/+/381316 Auto-Submit: Russ Cox Run-TryBot: Russ Cox Reviewed-by: Ian Lance Taylor Reviewed-by: Alan Donovan TryBot-Result: Gopher Robot Reviewed-by: Roland Shoemaker --- src/sync/atomic/doc.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/sync/atomic') diff --git a/src/sync/atomic/doc.go b/src/sync/atomic/doc.go index bb3b8f673e..4d426826da 100644 --- a/src/sync/atomic/doc.go +++ b/src/sync/atomic/doc.go @@ -36,6 +36,14 @@ // The load and store operations, implemented by the LoadT and StoreT // functions, are the atomic equivalents of "return *addr" and // "*addr = val". +// +// In the terminology of the Go memory model, if the effect of +// an atomic operation A is observed by atomic operation B, +// then A “synchronizes before” B. +// Additionally, all the atomic operations executed in a program +// behave as though executed in some sequentially consistent order. +// This definition provides the same semantics as +// C++'s sequentially consistent atomics and Java's volatile variables. package atomic import ( -- cgit v1.3