Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(488)

Delta Between Two Patch Sets: src/pkg/runtime/chan_test.go

Issue 110580043: code review 110580043: runtime: add fast paths to non-blocking channel operations (Closed)
Left Patch Set: Created 9 years, 8 months ago
Right Patch Set: diff -r f0b358f1d9727e8d0e2e1da848c2fa381e815341 https://dvyukov%40google.com@code.google.com/p/go/ Created 9 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/chan.goc ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package runtime_test 5 package runtime_test
6 6
7 import ( 7 import (
8 "runtime" 8 "runtime"
9 "sync" 9 "sync"
10 "sync/atomic" 10 "sync/atomic"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g ot %v/%v", chanCap, 0, chanCap, len(c), cap(c)) 188 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g ot %v/%v", chanCap, 0, chanCap, len(c), cap(c))
189 } 189 }
190 for i := 0; i < chanCap; i++ { 190 for i := 0; i < chanCap; i++ {
191 c <- i 191 c <- i
192 } 192 }
193 if len(c) != chanCap || cap(c) != chanCap { 193 if len(c) != chanCap || cap(c) != chanCap {
194 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g ot %v/%v", chanCap, chanCap, chanCap, len(c), cap(c)) 194 t.Fatalf("chan[%d]: bad len/cap, expect %v/%v, g ot %v/%v", chanCap, chanCap, chanCap, len(c), cap(c))
195 } 195 }
196 } 196 }
197 197
198 }
199 }
200
201 func TestNonblockRecvRace(t *testing.T) {
202 n := 10000
203 if testing.Short() {
204 n = 100
205 }
206 for i := 0; i < n; i++ {
207 c := make(chan int, 1)
208 c <- 1
209 go func() {
210 select {
211 case <-c:
212 default:
213 t.Fatal("chan is not ready")
214 }
215 }()
216 close(c)
217 <-c
198 } 218 }
199 } 219 }
200 220
201 func TestSelfSelect(t *testing.T) { 221 func TestSelfSelect(t *testing.T) {
202 // Ensure that send/recv on the same chan in select 222 // Ensure that send/recv on the same chan in select
203 // does not crash nor deadlock. 223 // does not crash nor deadlock.
204 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2)) 224 defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2))
205 for _, chanCap := range []int{0, 10} { 225 for _, chanCap := range []int{0, 10} {
206 var wg sync.WaitGroup 226 var wg sync.WaitGroup
207 wg.Add(2) 227 wg.Add(2)
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 func BenchmarkChanSem(b *testing.B) { 782 func BenchmarkChanSem(b *testing.B) {
763 type Empty struct{} 783 type Empty struct{}
764 myc := make(chan Empty, runtime.GOMAXPROCS(0)) 784 myc := make(chan Empty, runtime.GOMAXPROCS(0))
765 b.RunParallel(func(pb *testing.PB) { 785 b.RunParallel(func(pb *testing.PB) {
766 for pb.Next() { 786 for pb.Next() {
767 myc <- Empty{} 787 myc <- Empty{}
768 <-myc 788 <-myc
769 } 789 }
770 }) 790 })
771 } 791 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b