diff --git a/doc/articles/race_detector.html b/doc/articles/race_detector.html index 014411d948..63a658f870 100644 --- a/doc/articles/race_detector.html +++ b/doc/articles/race_detector.html @@ -379,6 +379,38 @@ func (w *Watchdog) Start() { } +
+As this example demonstrates, unsynchronized send and close operations +on the same channel can also be a race condition: +
+ +
+c := make(chan struct{}) // or buffered channel
+
+// The race detector cannot derive the happens before relation
+// for the following send and close operations. These two operations
+// are unsynchronized and happen concurrently.
+go func() { c <- struct{}{} }()
+close(c)
+
+
++According to the Go memory model, a send on a channel happens before +the corresponding receive from that channel completes. To synchronize +send and close operations, use a receive operation that guarantees +the send is done before the close: +
+ +
+c := make(chan struct{}) // or buffered channel
+
+go func() { c <- struct{}{} }()
+<-c
+close(c)
+
+