1 // $G $D/$F.go && $L $F.$A && ./$A.out
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Verify channel operations that test for blocking
8 // Use several sizes and types of operands
15 func i32receiver(c chan int32, strobe chan bool) {
22 func i32sender(c chan int32, strobe chan bool) {
27 func i64receiver(c chan int64, strobe chan bool) {
34 func i64sender(c chan int64, strobe chan bool) {
39 func breceiver(c chan bool, strobe chan bool) {
46 func bsender(c chan bool, strobe chan bool) {
51 func sreceiver(c chan string, strobe chan bool) {
58 func ssender(c chan string, strobe chan bool) {
63 var ticker = time.Tick(10 * 1000) // 10 us
72 const maxTries = 10000 // Up to 100ms per test.
81 var sync = make(chan bool)
83 for buffer := 0; buffer < 2; buffer++ {
84 c32 := make(chan int32, buffer)
85 c64 := make(chan int64, buffer)
86 cb := make(chan bool, buffer)
87 cs := make(chan string, buffer)
91 panic("blocked i32sender")
96 panic("blocked i64sender")
101 panic("blocked bsender")
106 panic("blocked ssender")
109 go i32receiver(c32, sync)
114 println("i32receiver buffer=", buffer)
121 go i32sender(c32, sync)
126 for i32, ok = <-c32; !ok; i32, ok = <-c32 {
129 println("i32sender buffer=", buffer)
135 panic("i32sender value")
141 go i64receiver(c64, sync)
143 for !(c64 <- 123456) {
152 go i64sender(c64, sync)
157 for i64, ok = <-c64; !ok; i64, ok = <-c64 {
165 panic("i64sender value")
171 go breceiver(cb, sync)
187 for b, ok = <-cb; !ok; b, ok = <-cb {
195 panic("bsender value")
201 go sreceiver(cs, sync)
203 for !(cs <- "hello") {
217 for s, ok = <-cs; !ok; s, ok = <-cs {
224 if s != "hello again" {
225 panic("ssender value")