forked from mirror/ants
Merge branch 'develop'
This commit is contained in:
parent
ce8f31e051
commit
8c76e9fa87
|
@ -145,6 +145,7 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
|
||||||
p.running++
|
p.running++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
<-p.freeSignal
|
||||||
w = workers[n]
|
w = workers[n]
|
||||||
workers[n] = nil
|
workers[n] = nil
|
||||||
p.workers = workers[:n]
|
p.workers = workers[:n]
|
||||||
|
@ -153,20 +154,13 @@ func (p *PoolWithFunc) getWorker() *WorkerWithFunc {
|
||||||
|
|
||||||
if waiting {
|
if waiting {
|
||||||
<-p.freeSignal
|
<-p.freeSignal
|
||||||
for {
|
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
workers = p.workers
|
workers = p.workers
|
||||||
l := len(workers) - 1
|
l := len(workers) - 1
|
||||||
if l < 0 {
|
|
||||||
p.lock.Unlock()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
w = workers[l]
|
w = workers[l]
|
||||||
workers[l] = nil
|
workers[l] = nil
|
||||||
p.workers = workers[:l]
|
p.workers = workers[:l]
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
break
|
|
||||||
}
|
|
||||||
} else if w == nil {
|
} else if w == nil {
|
||||||
w = &WorkerWithFunc{
|
w = &WorkerWithFunc{
|
||||||
pool: p,
|
pool: p,
|
||||||
|
|
Loading…
Reference in New Issue