diff options
author | Russ Cox <rsc@golang.org> | 2010-12-13 17:08:27 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-12-13 17:08:27 -0500 |
commit | 7ff68b365b68a7afa116b4dac0f1dcad989daa22 (patch) | |
tree | e11165d565eeba1d09e3c7b58d4f5b3bbe99e030 | |
parent | 951318c0dfb73a4ea48a6c98187f70722aa7c557 (diff) | |
download | go-7ff68b365b68a7afa116b4dac0f1dcad989daa22.tar.gz go-7ff68b365b68a7afa116b4dac0f1dcad989daa22.zip |
go_mem: goroutine exit is not special
R=r
CC=golang-dev
https://golang.org/cl/3628041
-rw-r--r-- | doc/go_mem.html | 29 |
1 files changed, 29 insertions, 0 deletions
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 <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> |