7 #ifndef TREELITE_OMP_EXCEPTION_H_ 8 #define TREELITE_OMP_EXCEPTION_H_ 22 std::exception_ptr omp_exception_;
30 template <
typename Function,
typename... Parameters>
31 void Run(Function f, Parameters... params) {
35 std::lock_guard<std::mutex> lock(mutex_);
36 if (!omp_exception_) {
37 omp_exception_ = std::current_exception();
39 }
catch (std::exception &ex) {
40 std::lock_guard<std::mutex> lock(mutex_);
41 if (!omp_exception_) {
42 omp_exception_ = std::current_exception();
51 if (this->omp_exception_) {
52 std::rethrow_exception(this->omp_exception_);
59 #endif // TREELITE_OMP_EXCEPTION_H_ Exception class that will be thrown by Treelite.
Exception class used throughout the Treelite codebase.
void Run(Function f, Parameters... params)
Parallel OMP blocks should be placed within Run to save exception.
OMP Exception class catches, saves and rethrows exception from OMP blocks.
void Rethrow()
should be called from the main thread to rethrow the exception