You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
just a very simple Go program
package main
import "fmt"
import "time"
func main() {
a:=make(chan int,10)
go func() {
for {
if(len(a)!=0) {
x:=<-a
fmt.Println(x)
if x==-1 {
break
}
}
}
}()
time.Sleep(2*time.Second)
a<-1
a<-2
a<-3
time.Sleep(2*time.Second)
a<-6
a<-7
a<- -1
time.Sleep(5*time.Second)
}
What did you expect to see?
the program should behave as if the line if (len(a))!=0 doesn't exist
that is channel a receive the data sent from main function and print it
it will print 1,2,3,6,7,-1 respectively
What did you see instead?
instead there is no print at all
if I print len(a), it will constantly show len(a)=0 rather than some positive value
in some sense channel a is not working? I don't know why
so the program can't stop
The text was updated successfully, but these errors were encountered:
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.9.1 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/yangyf/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build419888304=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
just a very simple Go program
What did you expect to see?
the program should behave as if the line if (len(a))!=0 doesn't exist
that is channel a receive the data sent from main function and print it
it will print 1,2,3,6,7,-1 respectively
What did you see instead?
instead there is no print at all
if I print len(a), it will constantly show len(a)=0 rather than some positive value
in some sense channel a is not working? I don't know why
so the program can't stop
The text was updated successfully, but these errors were encountered: