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