fixed race issue

This commit is contained in:
Andy Pan 2018-07-15 21:16:27 +08:00
parent 4d0682d342
commit 74e49c9f28
3 changed files with 4 additions and 1 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -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
}