Skip to content

Commit

Permalink
Merge pull request #9 from rfyiamcool/fix/cpu_load
Browse files Browse the repository at this point in the history
fix: polling cpu load
  • Loading branch information
xxjwxc authored Jun 12, 2023
2 parents 775f79b + e4b4bfd commit 23a9b62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
.DS_Store
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 23a9b62

Please sign in to comment.