Commit 504da53c authored by Russ Cox's avatar Russ Cox

runtime: select bug

The sanity checking in pass 2 is wrong
when a select is offering to communicate in
either direction on a channel and neither case
is immediately ready.

R=ken2
CC=golang-dev
https://golang.org/cl/3991047
parent 4608feb1
...@@ -732,25 +732,12 @@ loop: ...@@ -732,25 +732,12 @@ loop:
switch(cas->send) { switch(cas->send) {
case 0: // recv case 0: // recv
if(c->dataqsiz > 0) {
if(c->qcount > 0)
runtime·throw("select: pass 2 async recv");
} else {
if(dequeue(&c->sendq, c))
runtime·throw("select: pass 2 sync recv");
}
enqueue(&c->recvq, sg); enqueue(&c->recvq, sg);
break; break;
case 1: // send case 1: // send
if(c->dataqsiz > 0) { if(c->dataqsiz == 0)
if(c->qcount < c->dataqsiz)
runtime·throw("select: pass 2 async send");
} else {
if(dequeue(&c->recvq, c))
runtime·throw("select: pass 2 sync send");
c->elemalg->copy(c->elemsize, sg->elem, cas->u.elem); c->elemalg->copy(c->elemsize, sg->elem, cas->u.elem);
}
enqueue(&c->sendq, sg); enqueue(&c->sendq, sg);
break; break;
} }
......
...@@ -196,4 +196,13 @@ func main() { ...@@ -196,4 +196,13 @@ func main() {
case closedch <- 7: case closedch <- 7:
} }
}) })
// select should not get confused if it sees itself
testBlock(always, func() {
c := make(chan int)
select {
case c <- 1:
case <-c:
}
})
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment