1

add possibility to ask thread to suicide itself

This commit is contained in:
2022-07-22 21:38:56 +02:00
parent 16d7ae071d
commit db476093c7
2 changed files with 35 additions and 0 deletions

View File

@ -194,6 +194,34 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
cpu.enable_int();
}
// TODO: Can't retrive the thread right now because it's not clear when it's finished,
// maybe introduce a exited_queue and get it from there
void Scheduler::nice_kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
cpu.disable_int();
for (bse::unique_ptr<Thread>& thread : block_queue) {
if (thread->tid == tid) {
thread->suicide();
log << INFO << "Nice killed thread in block_queue with id: " << tid << endl;
deblock(tid);
cpu.enable_int();
return;
}
}
for (bse::unique_ptr<Thread>& thread : ready_queue) {
if (thread->tid == tid) {
thread->suicide();
log << INFO << "Nice killed thread in ready_queue with id: " << tid << endl;
cpu.enable_int();
return;
}
}
log << ERROR << "Can't nice kill thread (not found) with id: " << tid << endl;
cpu.enable_int();
}
/*****************************************************************************
* Methode: Scheduler::yield *
*---------------------------------------------------------------------------*

View File

@ -90,6 +90,13 @@ public:
void kill(unsigned int tid, bse::unique_ptr<Thread>* ptr);
void kill(unsigned int tid) { kill(tid, nullptr); }
// Ask thread to exit
// NOTE: I had many problems with killing threads that were stuck in some semaphore
// or were involved in any locking mechanisms, so with this a thread can make sure
// to "set things right" before exiting itself (but could also be ignored)
void nice_kill(unsigned int tid, bse::unique_ptr<Thread>* ptr);
void nice_kill(unsigned int tid) { nice_kill(tid, nullptr); }
// CPU freiwillig abgeben und Auswahl des naechsten Threads
void yield();