-static void
-do_worker(void *arg)
-{
- ThrPool *tp = (ThrPool *)arg;
- while (1) {
- ThrPool::job_t j;
- if (!tp->takeJob(&j))
- break; //die
-
- (void)(j.f)(j.a);
- }
-}
-
-//if blocking, then addJob() blocks when queue is full
-//otherwise, addJob() simply returns false when queue is full
-ThrPool::ThrPool(int sz, bool blocking)
-: nthreads_(sz),blockadd_(blocking),jobq_(100*sz)
-{
- for (int i = 0; i < sz; i++) {
- th_.push_back(std::thread(do_worker, this));
- }
+// if blocking, then addJob() blocks when queue is full
+// otherwise, addJob() simply returns false when queue is full
+ThrPool::ThrPool(size_t sz, bool blocking)
+: nthreads_(sz),blockadd_(blocking),jobq_(100*sz) {
+ for (size_t i=0; i<nthreads_; i++)
+ th_.emplace_back(&ThrPool::do_worker, this);