A better example to show the inhomogeneity of the selected possibilities of each case.
package main import "fmt" func main() { foo := make(chan struct{}) close(foo) var a, b, c, d, e, f, g float64 fa := func(){a++} fb := func(){b++} fc := func(){c++} fd := func(){d++} fe := func(){e++} ff := func(){f++} fg := func(){g++} for i := 0; i < 1000000; i++ { select { case <-foo: fa() case <-foo: fb() case <-foo: fc() case <-foo: fd() case <-foo: fe() case <-foo: ff() case <-foo: fg() } } fmt.Println(a/a) fmt.Println(b/a) fmt.Println(c/a) fmt.Println(d/a) fmt.Println(e/a) fmt.Println(f/a) fmt.Println(g/a) } result: 1 0.9999052991869258 0.9015652691532394 0.9691884140319548 0.966320332264567 0.9669020658305938 0.9604624105415533 On Friday, October 27, 2017 at 4:08:39 PM UTC-4, T L wrote: > > The following program constantly prints a value larger than 1.02 > > package main > > import "fmt" > > func main() { > foo, bar := make(chan struct{}), make(chan struct{}) > close(foo) > close(bar) > x, y := 0.0, 0.0 > f := func(){x++} > g := func(){y++} > for i := 0; i < 1000000; i++ { > select { > case <-bar: g() > case <-foo: f() > case <-bar: g() > case <-foo: f() > case <-bar: g() > case <-foo: f() > } > } > fmt.Println(x/y) > } > > if the last two cases are removed, then it becomes quit fair. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.