1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:10:04 -07:00

runtime/race: test that close synchronizes with read

Add a test to ensure that the race detector sees that closing a
channel synchronizes with a read from that channel.
This test case failed when CL 181543 was in the tree.
CL 181543 was reverted in CL 216158; this adds a test to make
sure that we don't re-introduce the problem at a later date.

For #32529
For #36714

Change-Id: I5a40f744c67c3f8191d6ad822710c180880a7375
Reviewed-on: https://go-review.googlesource.com/c/go/+/216099
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Ian Lance Taylor 2020-01-23 15:02:43 -08:00
parent 65367df477
commit 635a83047b

View File

@ -737,3 +737,29 @@ func TestNoRaceBlockedSelectSendSync(t *testing.T) {
case <-make(chan int):
}
}
// Test that close synchronizes with a read from the empty closed channel.
// See https://golang.org/issue/36714.
func TestNoRaceCloseHappensBeforeRead(t *testing.T) {
for i := 0; i < 100; i++ {
var loc int
var write = make(chan struct{})
var read = make(chan struct{})
go func() {
select {
case <-write:
_ = loc
default:
}
close(read)
}()
go func() {
loc = 1
close(write)
}()
<-read
}
}