On Mon, Jun 15, 2020 at 6:30 PM Leo Baltus <[email protected]> wrote:
>
> from gopl chapter 9.4 'Memory synchronisation’
>
> Synchronization primitives like channel communications and mutex operations
> cause the processor to flush out and commit all its accumulated writes so
> that the effects of goroutine execution up to that point are guaranteed to be
> visible to goroutines running on other processors.
>
> I would like to better understand how this works. What is it that makes this
> ‘flush out’ to happen? Is this a system call?
For example, the memory model allows this code
package main
var i int
func main() {
for {
i++
}
}
to never update the value of the i variable and use a value cached in
a CPU register. That means that other goroutines may not see the value
of i to ever change if there's no synchronization. Any synchronization
will force the register value to be actually stored in the i variable.
Such caching is an implementation detail, so it may or may not happen
with different targets and/or different Go compilers.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CAA40n-WKrbxs6iAHHMsDM3DzOLcmk4PaW9tgnYdwBGKJ%3DrbABA%40mail.gmail.com.