From 79bba39611e08e409bcaf66251763e41db0cf46c Mon Sep 17 00:00:00 2001 From: li_junsong Date: Fri, 4 Aug 2023 15:22:01 +0800 Subject: [PATCH] =?UTF-8?q?join=5Fset=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li_junsong --- ylong_runtime/src/task/join_set.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ylong_runtime/src/task/join_set.rs b/ylong_runtime/src/task/join_set.rs index fae744e..ddb903e 100644 --- a/ylong_runtime/src/task/join_set.rs +++ b/ylong_runtime/src/task/join_set.rs @@ -422,7 +422,7 @@ impl<'a, R> Builder<'a, R> { /// Cancels all task inside, and frees all corresponding JoinHandle. impl Drop for JoinSet { fn drop(&mut self) { - let mut list = self.list.lock().unwrap(); + let list = self.list.lock().unwrap(); for item in &list.done_list { unsafe { @@ -436,9 +436,17 @@ impl Drop for JoinSet { drop(ManuallyDrop::take(&mut *item.handle.get())); } } + let mut len = list.len; + drop(list); // pop every entry inside to reduce the ref count of the list - while list.done_list.pop_back().is_some() {} - list.wait_list.drain(); + while len != 0 { + let mut list = self.list.lock().unwrap(); + if list.done_list.pop_front().is_some() { + list.len -= 1; + len = list.len; + } + drop(list); + } } } -- Gitee