Skip to content

Commit

Permalink
Take deferred future into account for status query
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Jan 26, 2025
1 parent 716a99f commit 1676a41
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ std::tuple<void*, std::size_t, std::size_t> get_alloc_info(const void* devPtr,
template <typename T>
bool is_future_done(const T& future)
{
// If the future does not refer to a valid shared state.
if (!future.valid()) { return true; }

// If the future is returned from std::async(std::launch::deferred), its
// state is always deferred until wait() is called.
if (future.wait_for(std::chrono::seconds(0)) == std::future_status::deferred) {
future.wait();
return true;
}

// If the future is returned from std::async(std::launch:async).
return future.wait_for(std::chrono::seconds(0)) != std::future_status::timeout;
}

Expand Down

0 comments on commit 1676a41

Please sign in to comment.