Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
src/pkg/sync/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