Skip to content

Commit

Permalink
Tasks: Wait in destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatia committed Dec 18, 2024
1 parent 88c0ecb commit 1d379b1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tiledb/common/thread_pool/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ class ThreadPool {
: ThreadPoolTask(tp)
, f_(std::move(f)){};

/**
* Move is supported
*/
Task(Task&&) = default;
Task& operator=(Task&&) = default;

/**
* Disable copy and copy assignment
*/
Task(const Task&) = delete;
Task& operator=(const Task&) = delete;

/*
* Destructor waits for the task to be ready
*/
~Task() {
if (f_.valid()) {
try {
f_.wait();
} catch (...) {
return;
}
}
}

/**
* Wait in the threadpool for this task to be ready.
*/
Expand Down Expand Up @@ -158,6 +183,14 @@ class ThreadPool {
*/
SharedTask() = default;

/**
* Both copy and move are supported
*/
SharedTask(SharedTask&& t) = default;
SharedTask& operator=(SharedTask&& t) = default;
SharedTask(const SharedTask& t) = default;
SharedTask& operator=(const SharedTask& t) = default;

/**
* Constructor from std::future or std::shared_future
*/
Expand All @@ -172,6 +205,19 @@ class ThreadPool {
: ThreadPoolTask(t.tp_)
, f_(std::move(t.f_)){};

/*
* Destructor waits for the task to be ready
*/
~SharedTask() {
if (f_.valid()) {
try {
f_.wait();
} catch (...) {
return;
}
}
}

/**
* Wait in the threadpool for this task to be ready.
*/
Expand Down

0 comments on commit 1d379b1

Please sign in to comment.