From: Ian Lance Taylor Date: Thu, 23 Jan 2020 23:02:43 +0000 (-0800) Subject: runtime/race: test that close synchronizes with read X-Git-Tag: go1.15beta1~811 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=635a83047b4733f8cb3c9f5ac9d7c057622c2b52;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke --- diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go index 60e55ed66a..3e57b8221c 100644 --- a/src/runtime/race/testdata/chan_test.go +++ b/src/runtime/race/testdata/chan_test.go @@ -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 + } +}