Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / sync / once_test.go
blob155954a49b59b245317663608a086987ed04286f
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.
5 package sync_test
7 import (
8 . "sync"
9 "testing"
12 type one int
14 func (o *one) Increment() {
15 *o++
18 func run(once *Once, o *one, c chan bool) {
19 once.Do(func() { o.Increment() })
20 c <- true
23 func TestOnce(t *testing.T) {
24 o := new(one)
25 once := new(Once)
26 c := make(chan bool)
27 const N = 10
28 for i := 0; i < N; i++ {
29 go run(once, o, c)
31 for i := 0; i < N; i++ {
32 <-c
34 if *o != 1 {
35 t.Errorf("once failed: %d is not 1", *o)