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
5b4fa1ad
Commit
5b4fa1ad
authored
Mar 06, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document once
R=rsc DELTA=14 (7 added, 5 deleted, 2 changed) OCL=25818 CL=25834
parent
85647c94
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
once.go
src/lib/once.go
+9
-7
No files found.
src/lib/once.go
View file @
5b4fa1ad
...
@@ -2,13 +2,8 @@
...
@@ -2,13 +2,8 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
// For one-time initialization that is not done during init.
// This package provides a single function, Do, to run a function
// Wrap the initialization in a niladic function f() and call
// exactly once, usually used as part of initialization.
// once.Do(f)
// If multiple processes call once.Do(f) simultaneously
// with the same f argument, only one will call f, and the
// others will block until f finishes running.
package
once
package
once
import
"sync"
import
"sync"
...
@@ -21,6 +16,13 @@ type job struct {
...
@@ -21,6 +16,13 @@ type job struct {
var
jobs
=
make
(
map
[
func
()]
*
job
)
var
jobs
=
make
(
map
[
func
()]
*
job
)
var
joblock
sync
.
Mutex
;
var
joblock
sync
.
Mutex
;
// Do is the the only exported piece of the package.
// For one-time initialization that is not done during init,
// wrap the initialization in a niladic function f() and call
// Do(f)
// 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.
func
Do
(
f
func
())
{
func
Do
(
f
func
())
{
joblock
.
Lock
();
joblock
.
Lock
();
j
,
present
:=
jobs
[
f
];
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