Skip to content

Commit

Permalink
fix bug that nil in the taskBoxCh
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Jan 3, 2023
1 parent fe1e900 commit da506e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion util/gpool/spmc/spmcpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ func (p *Pool[T, U, C, CT, TF]) ReleaseAndWait() {
close(p.stopCh)
p.release()
for {
if p.Running() == 0 && p.heartbeatDone.Load() {
// Wait for all workers to exit and all task to be completed.
if p.Running() == 0 && p.heartbeatDone.Load() && p.waitingTask.Load() == 0 {
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion util/gpool/spmc/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (w *goWorker[T, U, C, CT, TF]) run() {
}()

for f := range w.taskBoxCh {
w.pool.subWaitingTask()
if f == nil {
return
}
w.pool.subWaitingTask()
ctx := f.GetContextFunc().GetContext()
if f.GetResultCh() != nil {
for t := range f.GetTaskCh() {
Expand Down

0 comments on commit da506e4

Please sign in to comment.