Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch8 exit实现存在bug #60

Open
MashPlant opened this issue Mar 24, 2022 · 4 comments
Open

ch8 exit实现存在bug #60

MashPlant opened this issue Mar 24, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@MashPlant
Copy link

https://rcore-os.github.io/rCore-Tutorial-Book-v3/chapter8/1thread-kernel.html 中说

如果进程/主线程先调用了 exit 系统调用来退出,那么整个进程(包括所属的所有线程)都会退出

但示例代码显然不能做到终止其他线程的运行,不用运行任何测试就能直接读出来。

当然这也可以用测试来验证。基于commit 9ad3bb4 ,运行如下测试:

#![no_std]
#![no_main]

#[macro_use]
extern crate user_lib;
extern crate alloc;

use user_lib::{thread_create, exit};
use alloc::vec::Vec;

pub fn thread_a() -> ! {
    for i in 0..1000 { print!("{}", i); }
    exit(1)
}

#[no_mangle]
pub fn main() -> i32 {
    thread_create(thread_a as usize, 0);
    println!("main thread exited.");
    exit(0)
}

可能的输出为:

>> exit_test
main thread exited.
[kernel] Panicked at src/sync/up.rs:27 already borrowed: BorrowMutError
[kernel] Panicked at src/task/processor.rs:94 called `Option::unwrap()` on a `None` value
[kernel] Panicked at src/task/processor.rs:94 called `Option::unwrap()` on a `None` value
[kernel] Panicked at src/task/processor.rs:94 called `Option::unwrap()` on a `None` value
...

虽然这段代码不太符合通常的正确代码的模式,但它也不应该让内核crash。

@wyfcyx
Copy link
Collaborator

wyfcyx commented Mar 24, 2022

Good catch!看起来我忘记在这里将就绪队列中同进程下的其他线程移除掉了。

@wyfcyx wyfcyx added the bug Something isn't working label Mar 24, 2022
@MashPlant
Copy link
Author

一个提示:可能还需要删除timer中的线程。

@wyfcyx
Copy link
Collaborator

wyfcyx commented May 21, 2022

目前在ch8上early_exitearly_exit2两个测例能跑了,ch9和main分支上涉及到I/O阻塞的部分还没改。

@chyyuu
Copy link
Member

chyyuu commented May 22, 2022

看来对于ch9/main branch还需进一步改进

chyyuu added a commit to LearningOS/rCore-Tutorial-Code-2023S that referenced this issue Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants