/** Wait for worker threads to exit */ void WaitExit() { boost::unique_lock<boost::mutex> lock(cs); while (numThreads > 0){ cond.wait(lock); } }
/** Thread function */ void Run() { ThreadCounter count(*this); while (running) { std::unique_ptr<WorkItem> i; { boost::unique_lock<boost::mutex> lock(cs); while (running && queue.empty()) cond.wait(lock); if (!running) break; i = std::move(queue.front()); queue.pop_front(); } (*i)(); } }
/** Thread function */ void Run() { ThreadCounter count(*this); while (running) { WorkItem* i = 0; { boost::unique_lock<boost::mutex> lock(cs); while (running && queue.empty()) cond.wait(lock); if (!running) break; i = queue.front(); queue.pop_front(); } (*i)(); delete i; } }