diff --git a/src/task.rs b/src/task.rs index fff918c..7d1c433 100644 --- a/src/task.rs +++ b/src/task.rs @@ -395,6 +395,19 @@ impl Task { let header = ptr as *const Header; unsafe { &*header } } + + /// Returns `true` if the current task is finished. + /// + /// Note that in a multithreaded environment, this task can change finish immediately after calling this function. + pub fn is_finished(&self) -> bool { + let ptr = self.ptr.as_ptr(); + let header = ptr as *const Header; + + unsafe { + let state = (*header).state.load(Ordering::Acquire); + state & (CLOSED | COMPLETED) != 0 + } + } } impl Drop for Task {