diff --git a/demo/taskpool/main.go b/demo/taskpool/main.go index 9472a16..8b9bf7a 100644 --- a/demo/taskpool/main.go +++ b/demo/taskpool/main.go @@ -66,4 +66,7 @@ func taskPool() { func main() { taskPool() //originGo() + nazalog.Debug("waiting exit.") + time.Sleep(1000 * time.Second) + //nazalog.Debug("bye.") } diff --git a/pkg/taskpool/pool.go b/pkg/taskpool/pool.go index bc62d7c..3fdf4aa 100644 --- a/pkg/taskpool/pool.go +++ b/pkg/taskpool/pool.go @@ -31,8 +31,11 @@ func (p *pool) Go(task Task) { // w = e.Value.(*Worker) // p.idleWorkerList.Remove(e) if len(p.idleWorkerList) != 0 { - w = p.idleWorkerList[0] - p.idleWorkerList = p.idleWorkerList[1:] + //w = p.idleWorkerList[0] + //p.idleWorkerList = p.idleWorkerList[1:] + + w = p.idleWorkerList[len(p.idleWorkerList)-1] + p.idleWorkerList = p.idleWorkerList[0:len(p.idleWorkerList)-1] atomic.AddInt32(&p.idleWorkerNum, -1) atomic.AddInt32(&p.busyWorkerNum, 1) }