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
49a5c28a
Commit
49a5c28a
authored
Oct 09, 2012
by
Dmitriy Vyukov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
io/ioutil: fix data race on rand
Fixes #4212. R=golang-dev, rsc CC=golang-dev
https://golang.org/cl/6641050
parent
d9018088
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
0 deletions
+4
-0
src/pkg/io/ioutil/tempfile.go
src/pkg/io/ioutil/tempfile.go
+4
-0
No files found.
src/pkg/io/ioutil/tempfile.go
View file @
49a5c28a
...
...
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strconv"
"sync"
"time"
)
...
...
@@ -16,18 +17,21 @@ import (
// chance the file doesn't exist yet - keeps the number of tries in
// TempFile to a minimum.
var
rand
uint32
var
randmu
sync
.
Mutex
func
reseed
()
uint32
{
return
uint32
(
time
.
Now
()
.
UnixNano
()
+
int64
(
os
.
Getpid
()))
}
func
nextSuffix
()
string
{
randmu
.
Lock
()
r
:=
rand
if
r
==
0
{
r
=
reseed
()
}
r
=
r
*
1664525
+
1013904223
// constants from Numerical Recipes
rand
=
r
randmu
.
Unlock
()
return
strconv
.
Itoa
(
int
(
1e9
+
r
%
1e9
))[
1
:
]
}
...
...
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