Skip to content

Commit

Permalink
Fix the missing atomic.Bool in go1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Nov 21, 2023
1 parent 322a4be commit 5f4149d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ants_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ func demoPoolFunc(args interface{}) {
time.Sleep(time.Duration(n) * time.Millisecond)
}

var stopLongRunningFunc atomic.Bool
var stopLongRunningFunc int32

func longRunningFunc() {
for !stopLongRunningFunc.Load() {
for atomic.LoadInt32(&stopLongRunningFunc) == 0 {
runtime.Gosched()
}
}

var stopLongRunningPoolFunc atomic.Bool
var stopLongRunningPoolFunc int32

func longRunningPoolFunc(arg interface{}) {
if ch, ok := arg.(chan struct{}); ok {
<-ch
return
}
for !stopLongRunningPoolFunc.Load() {
for atomic.LoadInt32(&stopLongRunningPoolFunc) == 0 {
runtime.Gosched()
}
}
Expand Down
8 changes: 4 additions & 4 deletions ants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,11 @@ func TestMultiPool(t *testing.T) {
n, _ = mp.FreeByIndex(i)
assert.EqualValues(t, 0, n)
}
stopLongRunningFunc.Store(true)
atomic.StoreInt32(&stopLongRunningFunc, 1)
assert.NoError(t, mp.ReleaseTimeout(3*time.Second))
assert.Zero(t, mp.Running())
assert.True(t, mp.IsClosed())
stopLongRunningFunc.Store(false)
atomic.StoreInt32(&stopLongRunningFunc, 0)
}
testFn()

Expand Down Expand Up @@ -1076,11 +1076,11 @@ func TestMultiPoolWithFunc(t *testing.T) {
n, _ = mp.FreeByIndex(i)
assert.EqualValues(t, 0, n)
}
stopLongRunningPoolFunc.Store(true)
atomic.StoreInt32(&stopLongRunningPoolFunc, 1)
assert.NoError(t, mp.ReleaseTimeout(3*time.Second))
assert.Zero(t, mp.Running())
assert.True(t, mp.IsClosed())
stopLongRunningPoolFunc.Store(false)
atomic.StoreInt32(&stopLongRunningPoolFunc, 0)
}
testFn()

Expand Down

0 comments on commit 5f4149d

Please sign in to comment.