From 7ff68b365b68a7afa116b4dac0f1dcad989daa22 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 13 Dec 2010 17:08:27 -0500 Subject: [PATCH] go_mem: goroutine exit is not special R=r CC=golang-dev https://golang.org/cl/3628041 --- doc/go_mem.html | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/doc/go_mem.html b/doc/go_mem.html index 78238900dd..35ada4ea63 100644 --- a/doc/go_mem.html +++ b/doc/go_mem.html @@ -143,6 +143,35 @@ calling hello will print "hello, world" at some point in the future (perhaps after hello has returned).

+

Goroutine destruction

+ +

+The exit of a goroutine is not guaranteed to happen before +any event in the program. For example, in this program: +

+ +
+var a string
+
+func hello() {
+	go func() { a = "hello" }()
+	print(a)
+}
+
+ +

+the assignment to a is not followed by +any synchronization event, so it is not guaranteed to be +observed by any other goroutine. +In fact, an aggressive compiler might delete the entire go statement. +

+ +

+If the effects of a goroutine must be observed by another goroutine, +use a synchronization mechanism such as a lock or channel +communiation to establish a relative ordering. +

+

Channel communication