Starry-OS / Starry

The main repository of Starry-OS, which will assemble all kernel components into a kernel according to a certain configuration.
Apache License 2.0
12 stars 18 forks source link

bug: When the leader thread exits, other threads don't exit immediately #23

Closed Azure-stars closed 1 month ago

Azure-stars commented 1 month ago

When the leader thread exits, it doesn't notify other threads. So even if other threads are woken up or scheduled, they will continue to run instead of exiting.

One solution is to send signal to other threads which belong to the same process, and call exit function when handling the signal.

if current_task.is_leader() {
      loop {
          let mut all_exited = true;
          for task in process.tasks.lock().deref() {
              if !task.is_leader() && task.state() != TaskState::Exited {
                  all_exited = false;
                  send_signal_to_thread(task.id().as_u64() as isize, SignalNo::SIGKILL as isize)
                      .unwrap();
              }
          }
          if !all_exited {
              yield_now();
          } else {
              break;
          }
      }
     ....
}
Azure-stars commented 1 month ago

commit: Starry-OS/axprocess@4cd862bff5653d076a7f8d33c6af98966fa9a76c