4 #include "lang/verify.h"
9 ThrPool *tp = (ThrPool *)arg;
19 //if blocking, then addJob() blocks when queue is full
20 //otherwise, addJob() simply returns false when queue is full
21 ThrPool::ThrPool(int sz, bool blocking)
22 : nthreads_(sz),blockadd_(blocking),jobq_(100*sz)
24 for (int i = 0; i < sz; i++) {
25 th_.push_back(std::thread(do_worker, this));
29 //IMPORTANT: this function can be called only when no external thread
30 //will ever use this thread pool again or is currently blocking on it
33 for (int i = 0; i < nthreads_; i++) {
35 j.f = (void (*)(void *))NULL; //poison pill to tell worker threads to exit
39 for (int i = 0; i < nthreads_; i++) {
45 ThrPool::addJob(void (*f)(void *), void *a)
51 return jobq_.enq(j,blockadd_);
55 ThrPool::takeJob(job_t *j)