If the effect of an atomic operation A is observed by atomic operation B, then A is synchronized before B.
By the latest version of Go Memory Model article: https://go.dev/ref/mem, will the following program always print 1?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4d9b8130-d06c-4519-9b99-d161e922d8f6n%40googlegroups.com.
I think the new memory model does not guarantee this program always prints 1:
1. There is no synchronization guarantee between line 13 and line 14
as these atomic operations are manipulated on the different memory
locations.
The memory operations in each goroutine must correspond to a correct sequential execution of that goroutine, given the values read from and written to memory. That execution must be consistent with the sequenced before relation, defined as the partial order requirements set out by the Go language specification for Go's control flow constructs as well as the order of evaluation for expressions.
> The memory operations in each goroutine must correspond to a correct sequential execution of that goroutine, given the values read from and written to memory. That execution must be consistent with the sequenced before relation, defined as the partial order requirements set out by the Go language specification for Go's control flow constructs as well as the order of evaluation for expressions.
This rule seems a bit unclear in its wording to me. These questions may occur:
1. What does it mean by "a correct sequential execution"? What defines
correct in this case? Is it implied by the variables' written order?
2. Is the rule applicable to multiple variables by written order or
only on different variables separately?
The first call to l.Unlock() (in f) is synchronized before the second call to l.Lock() (in main) returns, which is sequenced before the print.
> Any other reading, to me, is trying to find an ambiguity for the sole sake of finding an ambiguity.
A reader does not have to be motivated to find ambiguity. If the
sentence can be interpreted with different meanings, other readers may
perceive it differently. To me, the first read of this sentence is
perceived to be ambiguous regarding a single location or multiple
locations. The posted example discusses a and b as two memory
locations.
Atomic operations on a and b are two different statements. It remains
unclear where exactly is the sentence that tries to say this: atomic
operations on different memory locations obey the program statements
order within a goroutine.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3a266d04-db5c-4e16-bf1e-3ea6c7a98168n%40googlegroups.com.