From 3bc105aa44d6c2a4d1f6debf8fa715753cd41184 Mon Sep 17 00:00:00 2001 From: Diversantos Date: Sun, 1 Dec 2024 15:52:26 +0300 Subject: [PATCH] Golang race simulation and detection examlpe --- .../golang/cource/06i_code_quality/commands | 6 +++- .../golang/cource/06i_code_quality/race.go | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 examples/golang/cource/06i_code_quality/race.go diff --git a/examples/golang/cource/06i_code_quality/commands b/examples/golang/cource/06i_code_quality/commands index 9597eec..77c72c6 100644 --- a/examples/golang/cource/06i_code_quality/commands +++ b/examples/golang/cource/06i_code_quality/commands @@ -1,9 +1,13 @@ +# Profile go tool pprof pprof.out go tool pprof -http=:8080 pprof.out top list // list main.fib -go tool trace trace.out +# Tarce +go tool trace trace.out +# Race detection +go run --race diff --git a/examples/golang/cource/06i_code_quality/race.go b/examples/golang/cource/06i_code_quality/race.go new file mode 100644 index 0000000..33ee921 --- /dev/null +++ b/examples/golang/cource/06i_code_quality/race.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "time" +) + +func main() { + data := map[string]int{ + "Moscow": 100, + "Ekat": 70, + } + + go func() { + for i := 0; i < 5000; i++ { + data["Moscow"]++ + } + }() + + go func() { + for i := 0; i < 3000; i++ { + data["Ekat"]++ + } + }() + + time.Sleep(1 * time.Second) + fmt.Println("END Game") +} + +