fixed race issue

This commit is contained in:
Andy Pan 2018-07-15 21:09:59 +08:00
parent cc81c9573f
commit 4d0682d342
2 changed files with 6 additions and 6 deletions

View File

@ -76,7 +76,7 @@ func (p *Pool) monitorAndClear() {
n = i
w.task <- nil
idleWorkers[i] = nil
p.running--
atomic.AddInt32(&p.running, 1)
}
if n > 0 {
n++
@ -177,10 +177,10 @@ func (p *Pool) getWorker() *Worker {
workers := p.workers
n := len(workers) - 1
if n < 0 {
if p.running >= p.capacity {
if p.Running() >= p.Cap() {
waiting = true
} else {
p.running++
atomic.AddInt32(&p.running, 1)
}
} else {
<-p.freeSignal

View File

@ -77,7 +77,7 @@ func (p *PoolWithFunc) monitorAndClear() {
n = i
w.args <- nil
idleWorkers[i] = nil
p.running--
atomic.AddInt32(&p.running, 1)
}
if n > 0 {
n++
@ -182,10 +182,10 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
workers := p.workers
n := len(workers) - 1
if n < 0 {
if p.running >= p.capacity {
if p.Running() >= p.Cap() {
waiting = true
} else {
p.running++
atomic.AddInt32(&p.running, 1)
}
} else {
<-p.freeSignal