3 // if blocking, then addJob() blocks when queue is full
4 // otherwise, addJob() simply returns false when queue is full
5 thread_pool::thread_pool(size_t sz, bool blocking)
6 : nthreads_(sz),blockadd_(blocking),jobq_(100*sz) {
7 for (size_t i=0; i<nthreads_; i++)
8 th_.emplace_back(&thread_pool::do_worker, this);
11 // IMPORTANT: this function can be called only when no external thread
12 // will ever use this thread pool again or is currently blocking on it
13 thread_pool::~thread_pool() {
14 for (size_t i=0; i<nthreads_; i++)
17 for (size_t i=0; i<nthreads_; i++)
21 bool thread_pool::addJob(const job_t &j) {
22 return jobq_.enq(j,blockadd_);
25 void thread_pool::do_worker() {