Skip to content

Commit

Permalink
Merge pull request #146 from rcore-os/ch8-issue144
Browse files Browse the repository at this point in the history
bugfix #144: Do not free kstack when the main thread exits
  • Loading branch information
wyfcyx authored Mar 3, 2024
2 parents 1046976 + 49c982d commit f13b198
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions os/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ pub fn exit_current_and_run_next(exit_code: i32) {
process_inner.memory_set.recycle_data_pages();
// drop file descriptors
process_inner.fd_table.clear();
// remove all tasks
process_inner.tasks.clear();
// Remove all tasks except for the main thread itself.
// This is because we are still using the kstack under the TCB
// of the main thread. This TCB, including its kstack, will be
// deallocated when the process is reaped via waitpid.
while process_inner.tasks.len() > 1 {
process_inner.tasks.pop();
}
}
drop(process);
// we do not have to save task context
Expand Down

0 comments on commit f13b198

Please sign in to comment.