]> Cypherpunks repositories - gostls13.git/commitdiff
go_mem: goroutine exit is not special
authorRuss Cox <rsc@golang.org>
Mon, 13 Dec 2010 22:08:27 +0000 (17:08 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 13 Dec 2010 22:08:27 +0000 (17:08 -0500)
R=r
CC=golang-dev
https://golang.org/cl/3628041

doc/go_mem.html

index 78238900dda20631701211720d414f183db5d46f..35ada4ea635af44412e6548339a97a08b5bcef2e 100644 (file)
@@ -143,6 +143,35 @@ calling <code>hello</code> will print <code>"hello, world"</code>
 at some point in the future (perhaps after <code>hello</code> has returned).
 </p>
 
+<h3>Goroutine destruction</h3>
+
+<p>
+The exit of a goroutine is not guaranteed to happen before
+any event in the program.  For example, in this program:
+</p>
+
+<pre>
+var a string
+
+func hello() {
+       go func() { a = "hello" }()
+       print(a)
+}
+</pre>
+
+<p>
+the assignment to <code>a</code> 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 <code>go</code> statement.
+</p>
+
+<p>
+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.
+</p>
+
 <h3>Channel communication</h3>
 
 <p>