Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
2295554d
Commit
2295554d
authored
Mar 01, 2012
by
Dmitriy Vyukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync: add Once example
R=golang-dev, rsc, bradfitz CC=golang-dev
https://golang.org/cl/5715046
parent
986df83e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
example_test.go
src/pkg/sync/example_test.go
+20
-0
No files found.
src/pkg/sync/example_test.go
View file @
2295554d
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment