diff --git a/workpool/workpool.go b/workpool/workpool.go index aedf1af..1c6c100 100644 --- a/workpool/workpool.go +++ b/workpool/workpool.go @@ -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% } }