mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-16 18:11:03 +00:00
fixed race issue
This commit is contained in:
parent
4d0682d342
commit
74e49c9f28
@ -105,7 +105,6 @@ func TestCodeCov(t *testing.T) {
|
||||
t.Logf("pool with func, free workers number:%d", p.Free())
|
||||
p.ReSize(AntsSize / 2)
|
||||
t.Logf("pool with func, after resize, capacity:%d", p.Cap())
|
||||
|
||||
}
|
||||
|
||||
// func TestNoPool(t *testing.T) {
|
||||
|
||||
2
pool.go
2
pool.go
@ -145,10 +145,12 @@ func (p *Pool) Release() error {
|
||||
for i := 0; i < running; i++ {
|
||||
p.getWorker().task <- nil
|
||||
}
|
||||
p.lock.Lock()
|
||||
for i := range p.workers {
|
||||
p.workers[i] = nil
|
||||
}
|
||||
p.workers = nil
|
||||
p.lock.Unlock()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -150,10 +150,12 @@ func (p *PoolWithFunc) Release() error {
|
||||
for i := 0; i < running; i++ {
|
||||
p.getWorker().args <- nil
|
||||
}
|
||||
p.lock.Lock()
|
||||
for i := range p.workers {
|
||||
p.workers[i] = nil
|
||||
}
|
||||
p.workers = nil
|
||||
p.lock.Unlock()
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user