Skip to content

Commit bdd4b48

Browse files
committed
Default initialize and check for null threadpool in task classes
1 parent 77b52a2 commit bdd4b48

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tiledb/common/thread_pool/thread_pool.h

+17-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ThreadPool {
6060
protected:
6161
friend class ThreadPool;
6262

63-
ThreadPool* tp_;
63+
ThreadPool* tp_{nullptr};
6464

6565
/**
6666
* Pure virtual functions that tasks need to implement so that they can be
@@ -119,11 +119,16 @@ class ThreadPool {
119119
Task& operator=(const Task&) = delete;
120120

121121
/**
122-
* Wait in the threadpool for this task to be ready. Checks internally if a
123-
* task is valid.
122+
* Wait in the threadpool for this task to be ready.
124123
*/
125124
Status wait() {
126-
return tp_->wait(this);
125+
if (tp_ == nullptr) {
126+
throw std::runtime_error("Cannot wait, threadpool is not initialized.");
127+
} else if (!f_.valid()) {
128+
throw std::runtime_error("Cannot wait, task is invalid.");
129+
} else {
130+
return tp_->wait(this);
131+
}
127132
}
128133

129134
/**
@@ -234,11 +239,16 @@ class ThreadPool {
234239
}
235240

236241
/**
237-
* Wait in the threadpool for this task to be ready. Checks internally if a
238-
* task is valid.
242+
* Wait in the threadpool for this task to be ready.
239243
*/
240244
Status wait() {
241-
return tp_->wait(this);
245+
if (tp_ == nullptr) {
246+
throw std::runtime_error("Cannot wait, threadpool is not initialized.");
247+
} else if (!f_.valid()) {
248+
throw std::runtime_error("Cannot wait, shared task is invalid.");
249+
} else {
250+
return tp_->wait(this);
251+
}
242252
}
243253

244254
/**

0 commit comments

Comments
 (0)