Skip to content

Commit

Permalink
fix: polling cpu load
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool committed Jun 12, 2023
1 parent 4fbf750 commit e4b4bfd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion workpool/workpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,23 @@ func (p *WorkPool) startQueue() {
}

func (p *WorkPool) waitTask() {
var c int

for {
runtime.Gosched() // 出让时间片
c++

if p.IsDone() {
if atomic.LoadInt32(&p.isQueTask) == 0 {
break
}
}

if c <= 100 {
runtime.Gosched() // 出让时间片
continue
}

time.Sleep(20 * time.Microsecond) // 20us, cpu cost < 1%
}
}

Expand Down

0 comments on commit e4b4bfd

Please sign in to comment.