From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- gcc/testsuite/go.test/test/chan/doubleselect.go | 84 +++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 gcc/testsuite/go.test/test/chan/doubleselect.go (limited to 'gcc/testsuite/go.test/test/chan/doubleselect.go') diff --git a/gcc/testsuite/go.test/test/chan/doubleselect.go b/gcc/testsuite/go.test/test/chan/doubleselect.go new file mode 100644 index 000000000..592d2f54a --- /dev/null +++ b/gcc/testsuite/go.test/test/chan/doubleselect.go @@ -0,0 +1,84 @@ +// $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. + +// This test is designed to flush out the case where two cases of a select can +// both end up running. See http://codereview.appspot.com/180068. +package main + +import ( + "flag" + "runtime" +) + +var iterations *int = flag.Int("n", 100000, "number of iterations") + +// sender sends a counter to one of four different channels. If two +// cases both end up running in the same iteration, the same value will be sent +// to two different channels. +func sender(n int, c1, c2, c3, c4 chan<- int) { + defer close(c1) + defer close(c2) + + for i := 0; i < n; i++ { + select { + case c1 <- i: + case c2 <- i: + case c3 <- i: + case c4 <- i: + } + } +} + +// mux receives the values from sender and forwards them onto another channel. +// It would be simplier to just have sender's four cases all be the same +// channel, but this doesn't actually trigger the bug. +func mux(out chan<- int, in <-chan int) { + for { + v := <-in + if closed(in) { + close(out) + break + } + out <- v + } +} + +// recver gets a steam of values from the four mux's and checks for duplicates. +func recver(in <-chan int) { + seen := make(map[int]bool) + + for { + v := <-in + if closed(in) { + break + } + if _, ok := seen[v]; ok { + println("got duplicate value: ", v) + panic("fail") + } + seen[v] = true + } +} + +func main() { + runtime.GOMAXPROCS(2) + + c1 := make(chan int) + c2 := make(chan int) + c3 := make(chan int) + c4 := make(chan int) + cmux := make(chan int) + go sender(*iterations, c1, c2, c3, c4) + go mux(cmux, c1) + go mux(cmux, c2) + go mux(cmux, c3) + go mux(cmux, c4) + // We keep the recver because it might catch more bugs in the future. + // However, the result of the bug linked to at the top is that we'll + // end up panicing with: "throw: bad g->status in ready". + recver(cmux) + print("PASS\n") +} -- cgit v1.2.3