1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
16 func (o
*one
) Increment() {
20 func run(once
*Once
, o
*one
, c
chan bool) {
21 once
.Do(func() { o
.Increment() })
25 func TestOnce(t
*testing
.T
) {
30 for i
:= 0; i
< N
; i
++ {
33 for i
:= 0; i
< N
; i
++ {
37 t
.Errorf("once failed: %d is not 1", *o
)
41 func BenchmarkOnce(b
*testing
.B
) {
42 const CallsPerSched
= 1000
43 procs
:= runtime
.GOMAXPROCS(-1)
44 N
:= int32(b
.N
/ CallsPerSched
)
47 c
:= make(chan bool, procs
)
48 for p
:= 0; p
< procs
; p
++ {
50 for atomic
.AddInt32(&N
, -1) >= 0 {
52 for g
:= 0; g
< CallsPerSched
; g
++ {
59 for p
:= 0; p
< procs
; p
++ {