| 120 | } |
| 121 | |
| 122 | void ThreadPool::wait(bool checkForErrors) { |
| 123 | std::unique_lock<std::mutex> lock(mutex_); |
| 124 | if (!started_) |
| 125 | return; |
| 126 | completed_.wait(lock, [this] { return this->work_complete_; }); |
| 127 | started_ = false; |
| 128 | if (checkForErrors) { |
| 129 | // Check for errors |
| 130 | for (size_t i = 0; i < threads_.size(); ++i) { |
| 131 | if (!tl_errors_[i].empty()) { |
| 132 | // Throw the first error that occurred |
| 133 | std::stringstream ss; |
| 134 | ss << "Error in thread " << i << ": " << tl_errors_[i].front(); |
| 135 | std::string error = ss.str(); |
| 136 | tl_errors_[i].pop(); |
| 137 | throw std::runtime_error(error); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | int ThreadPool::getThreadsNum() const { |
| 144 | return threads_.size(); |
no test coverage detected