Skip to content

Commit 9c53801

Browse files
committed
refactor
1 parent 712a0a2 commit 9c53801

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ func MyFunc() {
4848
例如这样:
4949

5050
```
51-
go build -tags 'deadlock' myproject
51+
go build -tags deadlock myproject
5252
```
5353

5454
同样这个标签也用于单元测试,否则默认的单元测试会死锁:
5555

5656
```
57-
go test -tags 'deadlock'
57+
go test -tags deadlock -v
5858
```
5959

6060

README_EN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ When you need to compile a deadlock detection enabled version. Just add `deadloc
4848
For example:
4949

5050
```
51-
go build -tags 'deadlock' myproject
51+
go build -tags deadlock myproject
5252
```
5353

5454
This tag used for the unit test too. Otherwise the default unit test will deadlock:
5555

5656
```
57-
go test -tags 'deadlock'
57+
go test -tags deadlock -v
5858
```
5959

6060
How it works

sync_test.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import (
66
"time"
77
)
88

9+
func init() {
10+
go func() {
11+
for {
12+
time.Sleep(time.Second)
13+
}
14+
}()
15+
}
16+
917
func Benchmark_Lock1(b *testing.B) {
1018
var mutex sync.Mutex
1119
for i := 0; i < b.N; i++ {
@@ -26,12 +34,6 @@ func Test_DeadLock1(t *testing.T) {
2634
var testDone WaitGroup
2735
testDone.Add(1)
2836

29-
go func() {
30-
for {
31-
time.Sleep(time.Second)
32-
}
33-
}()
34-
3537
var mutex1 Mutex
3638

3739
go func() {
@@ -50,12 +52,6 @@ func Test_DeadLock2(t *testing.T) {
5052
var testDone WaitGroup
5153
testDone.Add(1)
5254

53-
go func() {
54-
for {
55-
time.Sleep(time.Second)
56-
}
57-
}()
58-
5955
var (
6056
mutex1 Mutex
6157
mutex2 Mutex
@@ -87,12 +83,6 @@ func Test_DeadLock3(t *testing.T) {
8783
var testDone WaitGroup
8884
testDone.Add(1)
8985

90-
go func() {
91-
for {
92-
time.Sleep(time.Second)
93-
}
94-
}()
95-
9686
var (
9787
mutex1 Mutex
9888
mutex2 Mutex

0 commit comments

Comments
 (0)