mirror of https://github.com/panjf2000/ants.git
🎏Fix a bug where invokers get stuck in waiting idle workers
This commit is contained in:
parent
af70ed0660
commit
08d01b6b48
15
pool.go
15
pool.go
|
@ -88,13 +88,6 @@ func (p *Pool) periodicallyPurge() {
|
|||
}
|
||||
p.workers = idleWorkers[:m]
|
||||
}
|
||||
|
||||
// There might be a situation that all workers have been cleaned up
|
||||
// while some invokers still get stuck in "p.cond.Wait()",
|
||||
// then it ought to wakes all those invokers.
|
||||
if len(p.workers) == 0 {
|
||||
p.cond.Broadcast()
|
||||
}
|
||||
p.lock.Unlock()
|
||||
|
||||
// Notify obsolete workers to stop.
|
||||
|
@ -105,6 +98,13 @@ func (p *Pool) periodicallyPurge() {
|
|||
w.task <- nil
|
||||
expiredWorkers[i] = nil
|
||||
}
|
||||
|
||||
// There might be a situation that all workers have been cleaned up(no any worker is running)
|
||||
// while some invokers still get stuck in "p.cond.Wait()",
|
||||
// then it ought to wakes all those invokers.
|
||||
if p.Running() == 0 {
|
||||
p.cond.Broadcast()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,6 +240,7 @@ func (p *Pool) retrieveWorker() *Worker {
|
|||
Reentry:
|
||||
p.cond.Wait()
|
||||
if p.Running() == 0 {
|
||||
p.lock.Unlock()
|
||||
spawnWorker()
|
||||
return w
|
||||
}
|
||||
|
|
15
pool_func.go
15
pool_func.go
|
@ -91,13 +91,6 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
|||
}
|
||||
p.workers = idleWorkers[:m]
|
||||
}
|
||||
|
||||
// There might be a situation that all workers have been cleaned up
|
||||
// while some invokers still get stuck in "p.cond.Wait()",
|
||||
// then it ought to wakes all those invokers.
|
||||
if len(p.workers) == 0 {
|
||||
p.cond.Broadcast()
|
||||
}
|
||||
p.lock.Unlock()
|
||||
|
||||
// Notify obsolete workers to stop.
|
||||
|
@ -108,6 +101,13 @@ func (p *PoolWithFunc) periodicallyPurge() {
|
|||
w.args <- nil
|
||||
expiredWorkers[i] = nil
|
||||
}
|
||||
|
||||
// There might be a situation that all workers have been cleaned up(no any worker is running)
|
||||
// while some invokers still get stuck in "p.cond.Wait()",
|
||||
// then it ought to wakes all those invokers.
|
||||
if p.Running() == 0 {
|
||||
p.cond.Broadcast()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,6 +245,7 @@ func (p *PoolWithFunc) retrieveWorker() *WorkerWithFunc {
|
|||
Reentry:
|
||||
p.cond.Wait()
|
||||
if p.Running() == 0 {
|
||||
p.lock.Unlock()
|
||||
spawnWorker()
|
||||
return w
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue