diff options
Diffstat (limited to 'src/pkg/sync/mutex_test.go')
-rw-r--r-- | src/pkg/sync/mutex_test.go | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/src/pkg/sync/mutex_test.go b/src/pkg/sync/mutex_test.go index 05fef786a..d0e048ed7 100644 --- a/src/pkg/sync/mutex_test.go +++ b/src/pkg/sync/mutex_test.go @@ -7,23 +7,23 @@ package sync_test import ( - "runtime"; - . "sync"; - "testing"; + "runtime" + . "sync" + "testing" ) func HammerSemaphore(s *uint32, loops int, cdone chan bool) { for i := 0; i < loops; i++ { - runtime.Semacquire(s); - runtime.Semrelease(s); + runtime.Semacquire(s) + runtime.Semrelease(s) } - cdone <- true; + cdone <- true } func TestSemaphore(t *testing.T) { - s := new(uint32); - *s = 1; - c := make(chan bool); + s := new(uint32) + *s = 1 + c := make(chan bool) for i := 0; i < 10; i++ { go HammerSemaphore(s, 1000, c) } @@ -33,37 +33,37 @@ func TestSemaphore(t *testing.T) { } func BenchmarkUncontendedSemaphore(b *testing.B) { - s := new(uint32); - *s = 1; - HammerSemaphore(s, b.N, make(chan bool, 2)); + s := new(uint32) + *s = 1 + HammerSemaphore(s, b.N, make(chan bool, 2)) } func BenchmarkContendedSemaphore(b *testing.B) { - b.StopTimer(); - s := new(uint32); - *s = 1; - c := make(chan bool); - runtime.GOMAXPROCS(2); - b.StartTimer(); + b.StopTimer() + s := new(uint32) + *s = 1 + c := make(chan bool) + runtime.GOMAXPROCS(2) + b.StartTimer() - go HammerSemaphore(s, b.N/2, c); - go HammerSemaphore(s, b.N/2, c); - <-c; - <-c; + go HammerSemaphore(s, b.N/2, c) + go HammerSemaphore(s, b.N/2, c) + <-c + <-c } func HammerMutex(m *Mutex, loops int, cdone chan bool) { for i := 0; i < loops; i++ { - m.Lock(); - m.Unlock(); + m.Lock() + m.Unlock() } - cdone <- true; + cdone <- true } func TestMutex(t *testing.T) { - m := new(Mutex); - c := make(chan bool); + m := new(Mutex) + c := make(chan bool) for i := 0; i < 10; i++ { go HammerMutex(m, 1000, c) } @@ -73,19 +73,19 @@ func TestMutex(t *testing.T) { } func BenchmarkUncontendedMutex(b *testing.B) { - m := new(Mutex); - HammerMutex(m, b.N, make(chan bool, 2)); + m := new(Mutex) + HammerMutex(m, b.N, make(chan bool, 2)) } func BenchmarkContendedMutex(b *testing.B) { - b.StopTimer(); - m := new(Mutex); - c := make(chan bool); - runtime.GOMAXPROCS(2); - b.StartTimer(); + b.StopTimer() + m := new(Mutex) + c := make(chan bool) + runtime.GOMAXPROCS(2) + b.StartTimer() - go HammerMutex(m, b.N/2, c); - go HammerMutex(m, b.N/2, c); - <-c; - <-c; + go HammerMutex(m, b.N/2, c) + go HammerMutex(m, b.N/2, c) + <-c + <-c } |