forked from mirror/ants
Fix an issue that blocks all waiting callers when all workers panic
Fixes #146 #147
This commit is contained in:
parent
2e763f1216
commit
dbcb6a104f
12
pool.go
12
pool.go
|
@ -243,16 +243,20 @@ func (p *Pool) retrieveWorker() (w *goWorker) {
|
|||
p.blockingNum++
|
||||
p.cond.Wait()
|
||||
p.blockingNum--
|
||||
if p.Running() == 0 {
|
||||
var nw int
|
||||
if nw = p.Running(); nw == 0 {
|
||||
p.lock.Unlock()
|
||||
if !p.IsClosed() {
|
||||
spawnWorker()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
w = p.workers.detach()
|
||||
if w == nil {
|
||||
if w = p.workers.detach(); w == nil {
|
||||
if nw < capacity {
|
||||
p.lock.Unlock()
|
||||
spawnWorker()
|
||||
return
|
||||
}
|
||||
goto Reentry
|
||||
}
|
||||
|
||||
|
|
|
@ -270,6 +270,11 @@ func (p *PoolWithFunc) retrieveWorker() (w *goWorkerWithFunc) {
|
|||
}
|
||||
l := len(p.workers) - 1
|
||||
if l < 0 {
|
||||
if p.Running() < p.Cap() {
|
||||
p.lock.Unlock()
|
||||
spawnWorker()
|
||||
return
|
||||
}
|
||||
goto Reentry
|
||||
}
|
||||
w = p.workers[l]
|
||||
|
|
|
@ -59,6 +59,8 @@ func (w *goWorker) run() {
|
|||
w.pool.options.Logger.Printf("worker exits from panic: %s\n", string(buf[:n]))
|
||||
}
|
||||
}
|
||||
// Call Signal() here in case there are goroutines waiting for available workers.
|
||||
w.pool.cond.Signal()
|
||||
}()
|
||||
|
||||
for f := range w.task {
|
||||
|
|
|
@ -59,6 +59,8 @@ func (w *goWorkerWithFunc) run() {
|
|||
w.pool.options.Logger.Printf("worker with func exits from panic: %s\n", string(buf[:n]))
|
||||
}
|
||||
}
|
||||
// Call Signal() here in case there are goroutines waiting for available workers.
|
||||
w.pool.cond.Signal()
|
||||
}()
|
||||
|
||||
for args := range w.args {
|
||||
|
|
Loading…
Reference in New Issue