goto asynch;
}
- if(raceenabled)
+ if(raceenabled) {
+ if(c->dataqsiz == 1)
+ runtime·raceacquire(chanbuf(c, c->sendx));
runtime·racerelease(chanbuf(c, c->sendx));
+ }
c->elemtype->alg->copy(c->elemsize, chanbuf(c, c->sendx), ep);
if(++c->sendx == c->dataqsiz)
goto asynch;
}
- if(raceenabled)
+ if(raceenabled) {
runtime·raceacquire(chanbuf(c, c->recvx));
+ if(c->dataqsiz == 1)
+ runtime·racerelease(chanbuf(c, c->recvx));
+ }
if(ep != nil)
c->elemtype->alg->copy(c->elemsize, ep, chanbuf(c, c->recvx));
if(cas->sg.elem != nil)
runtime·racewriteobjectpc(cas->sg.elem, c->elemtype, cas->pc, chanrecv);
runtime·raceacquire(chanbuf(c, c->recvx));
+ if(c->dataqsiz == 1)
+ runtime·racerelease(chanbuf(c, c->recvx));
}
if(cas->receivedp != nil)
*cas->receivedp = true;
asyncsend:
// can send to buffer
if(raceenabled) {
+ if(c->dataqsiz == 1)
+ runtime·raceacquire(chanbuf(c, c->sendx));
runtime·racerelease(chanbuf(c, c->sendx));
runtime·racereadobjectpc(cas->sg.elem, c->elemtype, cas->pc, chansend);
}
}
func TestRaceChanSameCell(t *testing.T) {
- c := make(chan int, 1)
+ c := make(chan int, 2)
v := 0
go func() {
v = 1
c <- 42
<-c
+ c <- 42
+ <-c
}()
time.Sleep(1e7)
c <- 43
c <- 0
<-compl
}
+
+func TestNoRaceChanMutex(t *testing.T) {
+ done := make(chan struct{})
+ mtx := make(chan struct{}, 1)
+ data := 0
+ go func() {
+ mtx <- struct{}{}
+ data = 42
+ <-mtx
+ done <- struct{}{}
+ }()
+ mtx <- struct{}{}
+ data = 43
+ <-mtx
+ <-done
+}
+
+func TestNoRaceSelectMutex(t *testing.T) {
+ done := make(chan struct{})
+ mtx := make(chan struct{}, 1)
+ aux := make(chan bool)
+ data := 0
+ go func() {
+ select {
+ case mtx <- struct{}{}:
+ case <-aux:
+ }
+ data = 42
+ select {
+ case <-mtx:
+ case <-aux:
+ }
+ done <- struct{}{}
+ }()
+ select {
+ case mtx <- struct{}{}:
+ case <-aux:
+ }
+ data = 43
+ select {
+ case <-mtx:
+ case <-aux:
+ }
+ <-done
+}
+
+func TestRaceChanSem(t *testing.T) {
+ done := make(chan struct{})
+ mtx := make(chan struct{}, 2)
+ data := 0
+ go func() {
+ mtx <- struct{}{}
+ data = 42
+ <-mtx
+ done <- struct{}{}
+ }()
+ mtx <- struct{}{}
+ data = 43
+ <-mtx
+ <-done
+}