On Wed, May 12, 2021 at 4:38 PM Ge <evergon...@gmail.com> wrote:
>
> According to https://golang.org/ref/spec#Defer_statements there is such an 
> expression:
>   `A "defer" statement invokes a function whose execution is deferred to the 
> moment the surrounding function returns`
>
> Does `defer` ensure  happens-before behaviour with non-defer code?

Happens before talks/defines properties/behavior of concurrently
executing goroutines. The deferred function is executed in the same
goroutine as its surrounding function. Any HB relations wrt other
goroutines are the same as if the deferred function was not deferred
but explicitly called before just returning from the surrounding
function.

>     However x86 allows out-of-order execution happening across function calls,

OOE and other peculiar CPU tricks should not be observable by the Go
program, modulo some side channel attacks.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-Um%3DTL3Qy00f8znvZyHPTUJ2WnHX31mpUu2BH4tUQWJ5g%40mail.gmail.com.

Reply via email to