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
) {
46 if r
:= recover(); r
== nil {
47 t
.Fatalf("Once.Do did not panic")
56 t
.Fatalf("Once.Do called twice")
60 func BenchmarkOnce(b
*testing
.B
) {
63 b
.RunParallel(func(pb
*testing
.PB
) {