1

adapt to scheduler rework

This commit is contained in:
2022-07-21 20:36:12 +02:00
parent 2ac36cda83
commit 017f7de650
13 changed files with 59 additions and 53 deletions

View File

@ -22,7 +22,7 @@ private:
KeyEventListener listener;
public:
KeyboardDemo() : listener(*this) {
KeyboardDemo() : listener(this->tid) {
log << INFO << "Initialized KeyboardDemo with ID: " << dec << this->tid << endl;
kevman.subscribe(this->listener);
}

View File

@ -7,6 +7,8 @@ void PreemptiveLoopThread::run() {
// Basic synchronization by semaphore
// NOTE: I placed the semaphore inside the CGA_Stream so multiple demos can synchronize, not
// only this one. This is optional so disruptions can still occur because of preemption
// (I only use this for the user output (demos), anywhere else could become problematic
// quickly...)
kout.lock();
// Saving + restoring kout position doesn't help much as preemption still occurs
@ -19,17 +21,13 @@ void PreemptiveLoopThread::run() {
void PreemptiveThreadDemo::run() {
kout << "Preemptive Thread Demo" << endl;
Thread* threads[this->number_of_threads];
kout << "Allocating LoopThreads" << endl;
for (unsigned int i = 0; i < this->number_of_threads; ++i) {
threads[i] = new PreemptiveLoopThread(i);
}
kout << "Adding threads to ready queue" << endl;
kout << "Readying LoopThreads" << endl;
for (unsigned int i = 0; i < this->number_of_threads; ++i) {
scheduler.ready(threads[i]);
threads.push_back(scheduler.ready<PreemptiveLoopThread>(i));
}
kout << "Exiting main thread" << endl;
while (listener.waitForKeyEvent() != 'L') {}
scheduler.exit();
}

View File

@ -25,12 +25,20 @@ private:
PreemptiveThreadDemo(const PreemptiveThreadDemo& copy) = delete; // Verhindere Kopieren
unsigned int number_of_threads;
bse::Vector<unsigned int> threads;
KeyEventListener listener;
public:
PreemptiveThreadDemo(unsigned int n) : number_of_threads(n) {
PreemptiveThreadDemo(unsigned int n) : number_of_threads(n), listener(this->tid) {
kout << "Initialized PreemptiveThreadDemo" << endl;
}
~PreemptiveThreadDemo() override {
for (unsigned int tid : threads) {
scheduler.kill(tid);
}
}
// Thread-Startmethode
void run() override;
};