From 3e45412327a2654a77944249962b3652e6142299 Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 17 Jan 2011 12:40:45 +0100 Subject: Imported Upstream version 2011.01.12 --- doc/go_mem.html | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'doc/go_mem.html') diff --git a/doc/go_mem.html b/doc/go_mem.html index 33bce5f7a..da45a07d7 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 +communication to establish a relative ordering. +

+

Channel communication

@@ -276,8 +305,9 @@ before the n+1'th call to l.Lock.

Once

-The once package provides a safe mechanism for -initialization in the presence of multiple goroutines. +The sync package provides a safe mechanism for +initialization in the presence of multiple goroutines +through the use of the Once type. Multiple threads can execute once.Do(f) for a particular f, but only one will run f(), and the other calls block until f() has returned. @@ -293,6 +323,7 @@ In this program:

 var a string
+var once sync.Once
 
 func setup() {
 	a = "hello, world"
-- 
cgit v1.2.3