Skip to content

Commit

Permalink
fixed:waitGroup data race
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiming1997 committed Sep 13, 2024
1 parent 23a9b62 commit 721000e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions workpool/workpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func New(max int) *WorkPool { // 注册工作池,并设置最大并发数
errChan: make(chan error, 1),
waitingQueue: myqueue.New(),
}

p.wg.Add(max) // Maximum number of work cycles,最大的工作协程数
go p.loop(max)
return p
}
Expand Down Expand Up @@ -127,7 +127,6 @@ func (p *WorkPool) waitTask() {
func (p *WorkPool) loop(maxWorkersCount int) {
go p.startQueue() // Startup queue , 启动队列

p.wg.Add(maxWorkersCount) // Maximum number of work cycles,最大的工作协程数
// Start Max workers, 启动max个worker
for i := 0; i < maxWorkersCount; i++ {
go func() {
Expand Down

0 comments on commit 721000e

Please sign in to comment.