Skip to content

Commit

Permalink
fix: dead lock
Browse files Browse the repository at this point in the history
  • Loading branch information
wathenjiang committed Sep 20, 2023
1 parent e325825 commit a11f80c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tokio/src/runtime/task/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl<S: 'static> OwnedTasks<S> {
let mut lock = self.lists[task_id.0 as usize & (self.grain - 1) as usize].lock();
// check close flag
if self.closed.load(Ordering::Acquire) {
drop(lock);
task.shutdown();
return None;
}
Expand Down Expand Up @@ -159,13 +160,15 @@ impl<S: 'static> OwnedTasks<S> {
self.closed.store(true, Ordering::Release);
for i in start..self.grain as usize + start {
loop {
let task = match self.lists[i & (self.grain - 1) as usize].lock().pop_back() {
let mut lock = self.lists[i & (self.grain - 1) as usize].lock();
let task = match lock.pop_back() {
Some(task) => {
self.count.fetch_sub(1, Ordering::Relaxed);
task
}
None => break,
};
drop(lock);
task.shutdown();
}
}
Expand Down

0 comments on commit a11f80c

Please sign in to comment.