On Mon, Jan 6, 2020 at 10:55 AM hao dong <hao.a.d...@gmail.com> wrote:
>
> After reading blog post : https://golang.org/ref/mem
>
> I got one question, in the code below:
>
>
> var c = make(chan int, 10)
> var a string
>
> func f() {
> a = "hello, world"
> c <- 0
> }
>
> func main() {
> go f()
> <-c
> print(a)
> }
>
>
> How can the complier knows that  a = "hello, world" happens  c <-0. Or could 
> it possible that  c <-0 happens first, a = "hello, world" happens second ??

The compiler ensures that the assignment to a happens before the send
operation on c.

If that doesn't answer your question, can you explain in more detail?

Ian

-- 
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/CAOyqgcXhAhaJVy4Ck32XccE26sTLO9zdzhRvkj5AG%3D5FfhdRnQ%40mail.gmail.com.

Reply via email to