Merge pull request #12697 from unknownbrackets/http

http: Correct new thread executor
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2020-03-10 09:54:58 +01:00
commit d527e5913f
2 files changed
+6 -4

No files matched your search

+4 -3
View File
@@ -10,13 +10,14 @@ void SameThreadExecutor::Run(std::function<void()> func) {
}
void NewThreadExecutor::Run(std::function<void()> func) {
thread_ = std::thread(func);
threads_.push_back(std::thread(func));
}
NewThreadExecutor::~NewThreadExecutor() {
// If Run was ever called...
if (thread_.joinable())
thread_.join();
for (auto &thread : threads_)
thread.join();
threads_.clear();
}
} // namespace threading
+2 -1
View File
@@ -2,6 +2,7 @@
#include <functional>
#include <thread>
#include <vector>
namespace threading {
@@ -23,7 +24,7 @@ public:
void Run(std::function<void()> func) override;
private:
std::thread thread_;
std::vector<std::thread> threads_;
};
} // namespace threading