Skip to content

Commit

Permalink
Merge pull request #10 from Yiming1997/fix/data-race
Browse files Browse the repository at this point in the history
fixed:waitGroup data race
  • Loading branch information
xxjwxc authored Sep 13, 2024
2 parents 23a9b62 + 721000e commit c22af3f
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 c22af3f

Please sign in to comment.