diff --git a/src/solver.cpp b/src/solver.cpp index 118af4c8d7..298caaf774 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -1035,7 +1035,7 @@ void Solver::setMaxTime(double maxtime) { void Solver::startTimer() const { simulation_timer_.reset(); } bool Solver::timeExceeded(int interval) const { - static int eval_counter = 0; + thread_local static int eval_counter = 0; // 0 means infinite time if (maxtime_.count() == 0) diff --git a/src/solver_cvodes.cpp b/src/solver_cvodes.cpp index 0b60304c55..efe50eb8a9 100644 --- a/src/solver_cvodes.cpp +++ b/src/solver_cvodes.cpp @@ -1126,7 +1126,8 @@ static int froot(realtype t, N_Vector x, realtype* root, void* user_data) { if (model->ne != model->ne_solver) { // temporary buffer to store all root function values, not only the ones // tracked by the solver - static std::vector root_buffer(model->ne, 0.0); + thread_local static std::vector root_buffer(model->ne, 0.0); + root_buffer.resize(model->ne); model->froot(t, x, root_buffer); std::copy_n(root_buffer.begin(), model->ne_solver, root); } else {