Skip to content

Commit

Permalink
Golang race simulation and detection examlpe
Browse files Browse the repository at this point in the history
  • Loading branch information
k8s4 committed Dec 1, 2024
1 parent 91fa564 commit 3bc105a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/golang/cource/06i_code_quality/commands
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Profile
go tool pprof pprof.out
go tool pprof -http=:8080 pprof.out

top
list <func> // list main.fib

go tool trace trace.out

# Tarce
go tool trace trace.out

# Race detection
go run --race <file.go>
30 changes: 30 additions & 0 deletions examples/golang/cource/06i_code_quality/race.go
Original file line number Diff line number Diff line change
@@ -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")
}


0 comments on commit 3bc105a

Please sign in to comment.