1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:44:40 -07:00

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
This commit is contained in:
Russ Cox 2011-01-28 17:17:38 -05:00
parent 4608feb18b
commit 504da53c85
2 changed files with 10 additions and 14 deletions

View File

@ -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;
} }

View File

@ -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:
}
})
} }