We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 83d1c3d commit 9945691Copy full SHA for 9945691
uuid.go
@@ -19,11 +19,20 @@ var (
19
generators [ng]gen
20
)
21
22
+func init() {
23
+ if (ng & ngmask) != 0 {
24
+ panic("uuid: you modified ng to create more gens, but it needs to be a power of 2")
25
+ }
26
+}
27
+
28
// V4 returns a UUIDv4. It never returns an error, never panics,
29
// and never runs out of entropy.
30
func V4() string {
31
i := 0
32
for {
33
+ // this is a spinlock, nothing starves these generators
34
+ // enough for anything more elaborate, as V4 completes
35
+ // in 25-100ns on modern systems
36
if atomic.CompareAndSwapUint32(&access[i], 0, 1) {
37
u := string(generators[i].V4())
38
atomic.StoreUint32(&access[i], 0)
0 commit comments