2008-07-16 15:41:27 -06:00
|
|
|
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Verify channel operations that test for blocking
|
|
|
|
// Use several sizes and types of operands
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
func pause() {
|
|
|
|
for i:=0; i<100; i++ { sys.gosched() }
|
|
|
|
}
|
|
|
|
|
|
|
|
func i32receiver(c *chan int32) {
|
2008-07-16 15:49:01 -06:00
|
|
|
if <-c != 123 { panic "i32 value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func i32sender(c *chan int32) {
|
2008-07-16 15:49:01 -06:00
|
|
|
c -< 234
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func i64receiver(c *chan int64) {
|
2008-07-16 15:49:01 -06:00
|
|
|
if <-c != 123456 { panic "i64 value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func i64sender(c *chan int64) {
|
2008-07-16 15:49:01 -06:00
|
|
|
c -< 234567
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func breceiver(c *chan bool) {
|
2008-07-16 15:49:01 -06:00
|
|
|
if ! <-c { panic "b value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func bsender(c *chan bool) {
|
|
|
|
c -< true
|
|
|
|
}
|
|
|
|
|
|
|
|
func sreceiver(c *chan string) {
|
2008-07-16 15:49:01 -06:00
|
|
|
if <-c != "hello" { panic "s value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func ssender(c *chan string) {
|
2008-07-16 15:49:01 -06:00
|
|
|
c -< "hello again"
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var i32 int32;
|
|
|
|
var i64 int64;
|
|
|
|
var b bool;
|
|
|
|
var s string;
|
|
|
|
var ok bool;
|
|
|
|
|
|
|
|
c32 := new(chan int32);
|
|
|
|
c64 := new(chan int64);
|
|
|
|
cb := new(chan bool);
|
|
|
|
cs := new(chan string);
|
|
|
|
|
|
|
|
i32, ok = <-c32;
|
|
|
|
if ok { panic "blocked i32sender" }
|
|
|
|
|
|
|
|
i64, ok = <-c64;
|
|
|
|
if ok { panic "blocked i64sender" }
|
|
|
|
|
|
|
|
b, ok = <-cb;
|
|
|
|
if ok { panic "blocked bsender" }
|
|
|
|
|
|
|
|
s, ok = <-cs;
|
|
|
|
if ok { panic "blocked ssender" }
|
|
|
|
|
|
|
|
go i32receiver(c32);
|
|
|
|
pause();
|
2008-07-16 15:49:01 -06:00
|
|
|
ok = c32 -< 123;
|
2008-07-16 15:41:27 -06:00
|
|
|
if !ok { panic "i32receiver" }
|
|
|
|
go i32sender(c32);
|
|
|
|
pause();
|
|
|
|
i32, ok = <-c32;
|
|
|
|
if !ok { panic "i32sender" }
|
2008-07-16 15:49:01 -06:00
|
|
|
if i32 != 234 { panic "i32sender value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
|
|
|
|
go i64receiver(c64);
|
|
|
|
pause();
|
2008-07-16 15:49:01 -06:00
|
|
|
ok = c64 -< 123456;
|
2008-07-16 15:41:27 -06:00
|
|
|
if !ok { panic "i64receiver" }
|
|
|
|
go i64sender(c64);
|
|
|
|
pause();
|
|
|
|
i64, ok = <-c64;
|
|
|
|
if !ok { panic "i64sender" }
|
2008-07-16 15:49:01 -06:00
|
|
|
if i64 != 234567 { panic "i64sender value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
|
|
|
|
go breceiver(cb);
|
|
|
|
pause();
|
|
|
|
ok = cb -< true;
|
|
|
|
if !ok { panic "breceiver" }
|
|
|
|
go bsender(cb);
|
|
|
|
pause();
|
|
|
|
b, ok = <-cb;
|
|
|
|
if !ok { panic "bsender" }
|
2008-07-16 15:49:01 -06:00
|
|
|
if !b{ panic "bsender value" }
|
2008-07-16 15:41:27 -06:00
|
|
|
|
|
|
|
go sreceiver(cs);
|
|
|
|
pause();
|
2008-07-16 15:49:01 -06:00
|
|
|
ok = cs -< "hello";
|
2008-07-16 15:41:27 -06:00
|
|
|
if !ok { panic "sreceiver" }
|
|
|
|
go ssender(cs);
|
|
|
|
pause();
|
|
|
|
s, ok = <-cs;
|
|
|
|
if !ok { panic "ssender" }
|
2008-07-16 15:49:01 -06:00
|
|
|
if s != "hello again" { panic "ssender value" }
|
|
|
|
print "PASS\n"
|
2008-07-16 15:41:27 -06:00
|
|
|
}
|