1
Files
lecture-operating-system-de…/c_os/user/demo/PreemptiveThreadDemo.h
2022-07-21 20:36:12 +02:00

47 lines
1.1 KiB
C++

#ifndef __preemptive_thread_include__
#define __preemptive_thread_include__
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
#include "lib/Semaphore.h"
class PreemptiveLoopThread : public Thread {
private:
int id;
// Semaphore* sem;
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
public:
// Gibt der Loop einen Stack und eine Id.
PreemptiveLoopThread(int i) : id(i) {}
// Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus.
void run() override;
};
class PreemptiveThreadDemo : public Thread {
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), listener(this->tid) {
kout << "Initialized PreemptiveThreadDemo" << endl;
}
~PreemptiveThreadDemo() override {
for (unsigned int tid : threads) {
scheduler.kill(tid);
}
}
// Thread-Startmethode
void run() override;
};
#endif