blob: b9c063dbc021fef10524231adcffb3ee41ff923b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// 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.
// GOMAXPROCS=10 gotest
package sync
import (
"sync";
"testing"
)
export func HammerSemaphore(s *int32, cdone chan bool) {
for i := 0; i < 1000; i++ {
semacquire(s);
semrelease(s);
}
cdone <- true;
}
export func TestSemaphore(t *testing.T) {
s := new(int32);
*s = 1;
c := make(chan bool);
for i := 0; i < 10; i++ {
go HammerSemaphore(s, c);
}
for i := 0; i < 10; i++ {
<-c;
}
}
export func HammerMutex(m *Mutex, cdone chan bool) {
for i := 0; i < 1000; i++ {
m.Lock();
m.Unlock();
}
cdone <- true;
}
export func TestMutex(t *testing.T) {
m := new(Mutex);
c := make(chan bool);
for i := 0; i < 10; i++ {
go HammerMutex(m, c);
}
for i := 0; i < 10; i++ {
<-c;
}
}
|