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

View File

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