Skip to content

Selects are always selecting the first case if multiple can proceed #2152

Closed
@gopherbot

Description

@gopherbot

by bjorn.tipling:

What steps will reproduce the problem?
1. Compile and run this code:
package main

import "fmt"

func main() {
        a := make(chan int)
        go func() {
                for {
                        fmt.Print(<-a)
                }
        } ()
        for {
                select {
                case a <- 0:
                case a <- 1:
                }
        }
}

2. See it just spit out 0's.

What is the expected output?

There should be a distribution of 0's and 1's, not just 0's.

What do you see instead?

Just 0's.

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

Mac OS X Lion 10.7

Which revision are you using?  (hg identify)

c17ce5ec06b4 weekly/weekly.2011-08-10 (Latest don't build on OS X Lion)

Please provide any additional information below.


IRC log from #go-nuts:

18:48 < s|k> just gives me 0's
18:49 < s|k> the random program
18:49 < s|k> http://pastie.org/2371134
19:51 < f2f> s|k, post to the list to see what's changed.
19:51 < f2f> it is certaonly contrary to the spec: "If multiple cases can
proceed, a pseudo-random fair choice is made to decide which single communication 
             will execute.
19:52 < f2f> "
19:52 < f2f> certainly even
19:52 < f2f> if you don't want to post to the list i will :)
19:59 < chilts> ok, so I downloaded and compiled that program and get lots of 0's
and 1's in random order
19:59 < chilts> (pseudo random order)
19:59 < f2f> i get lots of 0s. on osx 6g and linux 8g
20:00 < chilts> I'm on Linux : 6g version release.r59 9022
20:00 < chilts> seems fine to me
20:00 < f2f> hmm. still 0
20:01 < f2f> 9354 is my release
20:01 < f2f> 9414 for 8g
20:03 < f2f> let's see if i revert to 9022
20:05 < f2f> yes, i get random 0s and 1s at release 9022.
20:05 < f2f> s|k please report this violation of the spec.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions