From f2f7a694fa03dfec7a28621bd1d6bfb3d6d2bca9 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 19 May 2021 16:35:22 -0400 Subject: [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 Run-TryBot: Russ Cox Reviewed-by: Russ Cox X-Blog-Commit: ca2da54016440ba553b4b939b1ba248fd1d9b1bc --- blog/_content/race-detector.article | 23 ++++++++++++++++++++--- blog/support/racy/racy.go | 23 ----------------------- 2 files changed, 20 insertions(+), 26 deletions(-) delete mode 100644 blog/support/racy/racy.go 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`: + + 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 get -race golang.org/x/blog/support/racy - $ racy + $ 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 -} -- cgit v1.3