diff --git a/pool.go b/pool.go index 53471e2..cd10d2a 100644 --- a/pool.go +++ b/pool.go @@ -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 diff --git a/pool_func.go b/pool_func.go index d99269f..bd85f03 100644 --- a/pool_func.go +++ b/pool_func.go @@ -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