summaryrefslogtreecommitdiff
path: root/libgo/go/sync
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-03-06 17:57:23 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-03-06 17:57:23 +0000
commit593f74bbab63d34c7060918088bcbad686c31c66 (patch)
tree4ce83ca433796a728e9fdd00af105bce158532b5 /libgo/go/sync
parent46402cbe0ba3ea92be9642cf18eedaefe57a414c (diff)
libgo: Update to weekly.2012-03-04 release.
From-SVN: r185010
Diffstat (limited to 'libgo/go/sync')
-rw-r--r--libgo/go/sync/example_test.go20
-rw-r--r--libgo/go/sync/waitgroup.go15
2 files changed, 20 insertions, 15 deletions
diff --git a/libgo/go/sync/example_test.go b/libgo/go/sync/example_test.go
index 1424b1e79e6..15649240035 100644
--- a/libgo/go/sync/example_test.go
+++ b/libgo/go/sync/example_test.go
@@ -5,6 +5,7 @@
package sync_test
import (
+ "fmt"
"net/http"
"sync"
)
@@ -32,3 +33,22 @@ func ExampleWaitGroup() {
// Wait for all HTTP fetches to complete.
wg.Wait()
}
+
+func ExampleOnce() {
+ var once sync.Once
+ onceBody := func() {
+ fmt.Printf("Only once\n")
+ }
+ done := make(chan bool)
+ for i := 0; i < 10; i++ {
+ go func() {
+ once.Do(onceBody)
+ done <- true
+ }()
+ }
+ for i := 0; i < 10; i++ {
+ <-done
+ }
+ // Output:
+ // Only once
+}
diff --git a/libgo/go/sync/waitgroup.go b/libgo/go/sync/waitgroup.go
index 3e7d9d3c8f4..0165b1ffb2b 100644
--- a/libgo/go/sync/waitgroup.go
+++ b/libgo/go/sync/waitgroup.go
@@ -11,21 +11,6 @@ import "sync/atomic"
// goroutines to wait for. Then each of the goroutines
// runs and calls Done when finished. At the same time,
// Wait can be used to block until all goroutines have finished.
-//
-// For example:
-//
-// for i := 0; i < n; i++ {
-// if !condition(i) {
-// continue
-// }
-// wg.Add(1)
-// go func() {
-// // Do something.
-// wg.Done()
-// }()
-// }
-// wg.Wait()
-//
type WaitGroup struct {
m Mutex
counter int32