1
0
mirror of synced 2025-04-20 11:47:43 +03:00

Do not use shared_ptr where not required

This commit is contained in:
Johan Jansen 2019-10-31 21:48:48 +01:00
parent 58753ba33c
commit c652919954

View File

@ -370,8 +370,7 @@ class ThreadPool : public TaskQueue {
public: public:
explicit ThreadPool(size_t n) : shutdown_(false) { explicit ThreadPool(size_t n) : shutdown_(false) {
while (n) { while (n) {
auto t = std::make_shared<std::thread>(worker(*this)); threads_.emplace_back(worker(*this));
threads_.push_back(t);
n--; n--;
} }
} }
@ -395,8 +394,8 @@ public:
cond_.notify_all(); cond_.notify_all();
// Join... // Join...
for (auto t : threads_) { for (auto& t : threads_) {
t->join(); t.join();
} }
} }
@ -428,7 +427,7 @@ private:
}; };
friend struct worker; friend struct worker;
std::vector<std::shared_ptr<std::thread>> threads_; std::vector<std::thread> threads_;
std::list<std::function<void()>> jobs_; std::list<std::function<void()>> jobs_;
bool shutdown_; bool shutdown_;