1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
package grpool
import (
"fmt"
"runtime"
"github.com/ivpusic/grpool"
)
func second() {
numCPUs := runtime.NumCPU()
runtime.GOMAXPROCS(numCPUs)
// number of workers, and size of job queue
pool := grpool.NewPool(100, 50)
defer pool.Release()
// how many jobs we should wait
pool.WaitCount(10)
// submit one or more jobs to pool
for i := 0; i < 10; i++ {
count := i
pool.JobQueue <- func() {
// say that job is done, so we can know how many jobs are finished
defer pool.JobDone()
fmt.Printf("hello %d\n", count)
}
}
// wait until we call JobDone for all jobs
pool.WaitAll()
}
|