-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Golang race simulation and detection examlpe
- Loading branch information
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
||
|