mirror of https://github.com/panjf2000/ants.git
fixed race issue
This commit is contained in:
parent
cc81c9573f
commit
4d0682d342
6
pool.go
6
pool.go
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue