Skip to content

Commit 9a714ea

Browse files
committed
update exercise6
1 parent 6f7942d commit 9a714ea

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

exercise6/problem7/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Problem 7
22

3-
`runTasks` need to initialize some conf and we need to run it only once.
3+
Identify the data race in `task`. Fix the issue.
4+
5+
NOTE: don't forget to run test with `-race` flag

exercise6/problem7/problem7.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import (
66
"time"
77
)
88

9-
//TODO: identify the data race
10-
// fix the issue.
11-
129
func task() {
1310
start := time.Now()
1411
var t *time.Timer
1512
t = time.AfterFunc(
16-
randomDuration(), func() {
13+
randomDuration(),
14+
func() {
1715
fmt.Println(time.Now().Sub(start))
1816
t.Reset(randomDuration())
1917
},

exercise6/problem7/problem7_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ import (
66

77
func TestTask(t *testing.T) {
88
t.Run(
9-
"init should run one only once", func(t *testing.T) {
9+
"should avoid data race", func(t *testing.T) {
1010
task()
11-
12-
if 0 != 1 {
13-
t.Errorf("init function run times wrong")
14-
}
1511
},
1612
)
1713
}

0 commit comments

Comments
 (0)