diff options
| author | Russ Cox <rsc@golang.org> | 2021-05-19 16:35:22 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2021-05-21 00:22:44 +0000 |
| commit | f2f7a694fa03dfec7a28621bd1d6bfb3d6d2bca9 (patch) | |
| tree | ad32d9cbbc5a9bd42274d7bbd1374c67fc728f5d | |
| parent | 7267ca91e4d522f0810ea59656057307eadc6d7c (diff) | |
| download | go-x-website-f2f7a694fa03dfec7a28621bd1d6bfb3d6d2bca9.tar.xz | |
[x/blog] support/racy: delete program, inline into article
Change-Id: I1ba0d4aacdf23cf3378c7ab82af78d3940aff136
Reviewed-on: https://go-review.googlesource.com/c/blog/+/321669
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
X-Blog-Commit: ca2da54016440ba553b4b939b1ba248fd1d9b1bc
| -rw-r--r-- | blog/_content/race-detector.article | 23 | ||||
| -rw-r--r-- | blog/support/racy/racy.go | 23 |
2 files changed, 20 insertions, 26 deletions
diff --git a/blog/_content/race-detector.article b/blog/_content/race-detector.article index 5a9a0a7e..657bec40 100644 --- a/blog/_content/race-detector.article +++ b/blog/_content/race-detector.article @@ -63,10 +63,27 @@ To build your code with the race detector enabled, just add the $ go build -race mycmd // build the command $ go install -race mypkg // install the package -To try out the race detector for yourself, fetch and run this example program: +To try out the race detector for yourself, copy this example program into `racy.go`: - $ go get -race golang.org/x/blog/support/racy - $ racy + package main + + import "fmt" + + func main() { + done := make(chan bool) + m := make(map[string]string) + m["name"] = "world" + go func() { + m["name"] = "data race" + done <- true + }() + fmt.Println("Hello,", m["name"]) + <-done + } + +Then run it with the race detector enabled: + + $ go run -race racy.go ## Examples diff --git a/blog/support/racy/racy.go b/blog/support/racy/racy.go deleted file mode 100644 index e23ba9ba..00000000 --- a/blog/support/racy/racy.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build !appengine - -// This program demonstrates a race condition. -// To observe the race with the race detector, build with -race. -package main - -import "fmt" - -func main() { - done := make(chan bool) - m := make(map[string]string) - m["name"] = "world" - go func() { - m["name"] = "data race" - done <- true - }() - fmt.Println("Hello,", m["name"]) - <-done -} |
