1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:46:47 -07:00

runtime: catch races between channel close and channel send in select

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/10137043
This commit is contained in:
Dmitriy Vyukov 2013-06-10 22:58:04 +04:00
parent 06f55f5009
commit 62747bde6c
2 changed files with 27 additions and 3 deletions

View File

@ -186,7 +186,6 @@ runtime·chansend(ChanType *t, Hchan *c, byte *ep, bool *pres, void *pc)
}
runtime·lock(c);
// TODO(dvyukov): add similar instrumentation to select.
if(raceenabled)
runtime·racereadpc(c, pc, runtime·chansend);
if(c->closed)
@ -946,6 +945,8 @@ loop:
break;
case CaseSend:
if(raceenabled)
runtime·racereadpc(c, cas->pc, runtime·chansend);
if(c->closed)
goto sclose;
if(c->dataqsiz > 0) {

View File

@ -311,12 +311,35 @@ func TestRaceChanSendClose(t *testing.T) {
go func() {
defer func() {
recover()
compl <- true
}()
c <- 1
compl <- true
}()
go func() {
time.Sleep(1e7)
time.Sleep(10 * time.Millisecond)
close(c)
compl <- true
}()
<-compl
<-compl
}
func TestRaceChanSendSelectClose(t *testing.T) {
compl := make(chan bool, 2)
c := make(chan int, 1)
c1 := make(chan int)
go func() {
defer func() {
recover()
compl <- true
}()
time.Sleep(10 * time.Millisecond)
select {
case c <- 1:
case <-c1:
}
}()
go func() {
close(c)
compl <- true
}()