Skip to content

Commit b7260f2

Browse files
Make legate::Time resilient to the post-shutdown destruction (#395)
* Make legate::Time resilient to the post-shutdown destruction * Update src/timing/timing.cc Co-authored-by: Jacob Faibussowitsch <jacob.fai@gmail.com> --------- Co-authored-by: Jacob Faibussowitsch <jacob.fai@gmail.com>
1 parent 1cd33cf commit b7260f2

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/timing/timing.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include "timing/timing.h"
1414

15+
#include "core/runtime/detail/runtime.h"
16+
1517
#include "legion.h"
1618

1719
#include <optional>
@@ -20,18 +22,30 @@ namespace legate::timing {
2022

2123
class Time::Impl {
2224
public:
23-
explicit Impl(Legion::Future future) : future_{std::move(future)} {}
25+
explicit Impl(Legion::Future future)
26+
: future_{std::make_unique<Legion::Future>(std::move(future))}
27+
{
28+
}
29+
30+
~Impl()
31+
{
32+
if (!detail::Runtime::get_runtime()->initialized()) {
33+
// Leak the Future handle if the runtime has already shut down, as there's no hope that
34+
// this would be collected by the Legion runtime
35+
static_cast<void>(future_.release());
36+
}
37+
}
2438

2539
[[nodiscard]] int64_t value()
2640
{
2741
if (!value_) {
28-
value_ = future_.get_result<int64_t>();
42+
value_ = future_->get_result<int64_t>();
2943
}
3044
return *value_;
3145
}
3246

3347
private:
34-
Legion::Future future_{};
48+
std::unique_ptr<Legion::Future> future_{};
3549
std::optional<int64_t> value_{std::nullopt};
3650
};
3751

0 commit comments

Comments
 (0)