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 // GOMAXPROCS=10 gotest
15 func HammerSemaphore(s *uint32, loops int, cdone chan bool) {
16 for i := 0; i < loops; i++ {
23 func TestSemaphore(t *testing.T) {
27 for i := 0; i < 10; i++ {
28 go HammerSemaphore(s, 1000, c)
30 for i := 0; i < 10; i++ {
35 func BenchmarkUncontendedSemaphore(b *testing.B) {
38 HammerSemaphore(s, b.N, make(chan bool, 2))
41 func BenchmarkContendedSemaphore(b *testing.B) {
49 go HammerSemaphore(s, b.N/2, c)
50 go HammerSemaphore(s, b.N/2, c)
56 func HammerMutex(m *Mutex, loops int, cdone chan bool) {
57 for i := 0; i < loops; i++ {
64 func TestMutex(t *testing.T) {
67 for i := 0; i < 10; i++ {
68 go HammerMutex(m, 1000, c)
70 for i := 0; i < 10; i++ {
75 func BenchmarkUncontendedMutex(b *testing.B) {
77 HammerMutex(m, b.N, make(chan bool, 2))
80 func BenchmarkContendedMutex(b *testing.B) {
87 go HammerMutex(m, b.N/2, c)
88 go HammerMutex(m, b.N/2, c)