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
8afc6008
Commit
8afc6008
authored
Jul 13, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add note about once and closures
R=r DELTA=13 (13 added, 0 deleted, 0 changed) OCL=31535 CL=31549
parent
32cd8875
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
src/pkg/once/once.go
src/pkg/once/once.go
+13
-0
No files found.
src/pkg/once/once.go
View file @
8afc6008
...
...
@@ -23,6 +23,19 @@ var joblock sync.Mutex;
// If multiple processes call Do(f) simultaneously
// with the same f argument, only one will call f, and the
// others will block until f finishes running.
//
// Since a func() expression typically evaluates to a differerent
// function value each time it is evaluated, it is incorrect to
// pass such values to Do. For example,
// func f(x int) {
// Do(func() { fmt.Println(x) })
// }
// behaves the same as
// func f(x int) {
// fmt.Println(x)
// }
// because the func() expression in the first creates a new
// func each time f runs, and each of those funcs is run once.
func
Do
(
f
func
())
{
joblock
.
Lock
();
j
,
present
:=
jobs
[
f
];
...
...
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