Skip to content

Commit

Permalink
Join threads before deleting to avoid crashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfalbel committed Nov 5, 2024
1 parent c5c9082 commit b504d27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 6 additions & 0 deletions inst/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class ThreadPool {
void push (std::packaged_task<T()>&& task) {
this->event_loop.schedule(std::move(task));
}
~ThreadPool() {
this->event_loop.stopWhenEmpty();
for(auto& thread : threads) {
thread.join();
}
}
};

template <class type>
Expand Down
1 change: 0 additions & 1 deletion src/autograd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ namespace {
static EventLoop<void*> gTasks;
static EventLoop<void> gBackwardTasks;
static std::atomic<bool> backward_is_running(false);
//static ThreadPool<void>* pool;

void schedule_backward_task(std::packaged_task<void()>&& task) {
static ThreadPool<void> pool(5);
Expand Down

0 comments on commit b504d27

Please sign in to comment.