diff options
| author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-06 17:57:23 +0000 |
|---|---|---|
| committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-06 17:57:23 +0000 |
| commit | 220a902afa4e096172926d498e1efac23e80deb7 (patch) | |
| tree | 4ce83ca433796a728e9fdd00af105bce158532b5 /libgo/go/sync | |
| parent | 506056fd6ecd06499e2ee7f6e37dbd5fbf7f4de6 (diff) | |
| download | ppe42-gcc-220a902afa4e096172926d498e1efac23e80deb7.tar.gz ppe42-gcc-220a902afa4e096172926d498e1efac23e80deb7.zip | |
libgo: Update to weekly.2012-03-04 release.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@185010 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/sync')
| -rw-r--r-- | libgo/go/sync/example_test.go | 20 | ||||
| -rw-r--r-- | libgo/go/sync/waitgroup.go | 15 |
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 |

