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.
14 func (o
*one
) Increment() {
18 func run(t
*testing
.T
, once
*Once
, o
*one
, c
chan bool) {
19 once
.Do(func() { o
.Increment() })
21 t
.Errorf("once failed inside run: %d is not 1", v
)
26 func TestOnce(t
*testing
.T
) {
31 for i
:= 0; i
< N
; i
++ {
34 for i
:= 0; i
< N
; i
++ {
38 t
.Errorf("once failed outside run: %d is not 1", *o
)
42 func TestOncePanic(t
*testing
.T
) {
44 for i
:= 0; i
< 2; i
++ {
48 t
.Fatalf("Once.Do() has not panic'ed")
58 t
.Fatalf("Once called twice")
62 func BenchmarkOnce(b
*testing
.B
) {
65 b
.RunParallel(func(pb
*testing
.PB
) {