summaryrefslogtreecommitdiff
path: root/Kernel/Scheduler.cpp
diff options
context:
space:
mode:
authorCristian-Bogdan SIRB <cbsirb@gmail.com>2020-02-18 14:28:28 +0200
committerAndreas Kling <kling@serenityos.org>2020-02-26 13:06:40 +0100
commit717cd5015e91495fc28cbbe83576530905047faf (patch)
treea6c4328c16ab96d480b38622cc32e20affe3067f /Kernel/Scheduler.cpp
parent9fcb37ad30f6ba16d35a6e4a65f53f5dd8cbdbcb (diff)
downloadserenity-717cd5015e91495fc28cbbe83576530905047faf.zip
Kernel: Allow process with multiple threads to call exec and exit
This allows a process wich has more than 1 thread to call exec, even from a thread. This kills all the other threads, but it won't wait for them to finish, just makes sure that they are not in a running/runable state. In the case where a thread does exec, the new program PID will be the thread TID, to keep the PID == TID in the new process. This introduces a new function inside the Process class, kill_threads_except_self which is called on exit() too (exit with multiple threads wasn't properly working either). Inside the Lock class, there is the need for a new function, clear_waiters, which removes all the waiters from the Process::big_lock. This is needed since after a exit/exec, there should be no other threads waiting for this lock, the threads should be simply killed. Only queued threads should wait for this lock at this point, since blocked threads are handled in set_should_die.
Diffstat (limited to 'Kernel/Scheduler.cpp')
-rw-r--r--Kernel/Scheduler.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Kernel/Scheduler.cpp b/Kernel/Scheduler.cpp
index e8b67b1d59..8b7b8d7124 100644
--- a/Kernel/Scheduler.cpp
+++ b/Kernel/Scheduler.cpp
@@ -409,6 +409,9 @@ bool Scheduler::pick_next()
if (thread->process().is_being_inspected())
continue;
+ if (thread->process().exec_tid() && thread->process().exec_tid() != thread->tid())
+ continue;
+
ASSERT(thread->state() == Thread::Runnable || thread->state() == Thread::Running);
if (!thread_to_schedule) {