update preemption demo
This commit is contained in:
@ -1,17 +0,0 @@
|
|||||||
#include "user/PreemptiveLoopThread.h"
|
|
||||||
|
|
||||||
void PreemptiveLoopThread::run() {
|
|
||||||
|
|
||||||
/* Hier muss Code eingefuegt werden */
|
|
||||||
|
|
||||||
int cnt = 0;
|
|
||||||
while (true) {
|
|
||||||
// Basic synchronization by semaphore
|
|
||||||
sem->p();
|
|
||||||
|
|
||||||
kout.setpos(55, this->id);
|
|
||||||
kout << this->id << ": " << dec << cnt++ << endl;
|
|
||||||
|
|
||||||
sem->v();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
#ifndef __preemptive_thread_include__
|
|
||||||
#define __preemptive_thread_include__
|
|
||||||
|
|
||||||
#include "kernel/Globals.h"
|
|
||||||
#include "kernel/threads/Thread.h"
|
|
||||||
#include "user/PreemptiveLoopThread.h"
|
|
||||||
|
|
||||||
class PreemptiveThreadDemo : public Thread {
|
|
||||||
private:
|
|
||||||
PreemptiveThreadDemo(const PreemptiveThreadDemo& copy) = delete; // Verhindere Kopieren
|
|
||||||
|
|
||||||
public:
|
|
||||||
PreemptiveThreadDemo() {
|
|
||||||
kout << "Initialized PreemptiveThreadDemo" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Thread-Startmethode
|
|
||||||
void run() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,11 +1,23 @@
|
|||||||
#include "user/PreemptiveThreadDemo.h"
|
#include "user/demo/PreemptiveThreadDemo.h"
|
||||||
#include "lib/Semaphore.h"
|
|
||||||
|
void PreemptiveLoopThread::run() {
|
||||||
|
int cnt = 0;
|
||||||
|
while (true) {
|
||||||
|
// Basic synchronization by semaphore
|
||||||
|
sem->p();
|
||||||
|
|
||||||
|
kout.setpos(55, this->id);
|
||||||
|
kout << this->id << ": " << dec << cnt++ << endl;
|
||||||
|
|
||||||
|
sem->v();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreemptiveThreadDemo::run() {
|
void PreemptiveThreadDemo::run() {
|
||||||
kout << "PreemptiveThreadDemo ====================================" << endl;
|
kout << "PreemptiveThreadDemo ====================================" << endl;
|
||||||
kout << "Initializing Semaphore" << endl;
|
kout << "Initializing Semaphore" << endl;
|
||||||
Semaphore* sem = new Semaphore(1); // Create this semaphore on the heap as this thread exits itself,
|
Semaphore* sem = new Semaphore(1); // Create this semaphore on the heap as this thread exits itself,
|
||||||
// so stack allocated objects will be lost
|
// so stack allocated objects will be lost
|
||||||
|
|
||||||
kout << "Allocating LoopThread A" << endl;
|
kout << "Allocating LoopThread A" << endl;
|
||||||
Thread* cntA = new PreemptiveLoopThread(0, sem);
|
Thread* cntA = new PreemptiveLoopThread(0, sem);
|
||||||
@ -1,12 +1,11 @@
|
|||||||
#ifndef __pre_loopthread_include__
|
#ifndef __preemptive_thread_include__
|
||||||
#define __pre_loopthread_include__
|
#define __preemptive_thread_include__
|
||||||
|
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
#include "kernel/threads/Thread.h"
|
#include "kernel/threads/Thread.h"
|
||||||
#include "lib/Semaphore.h"
|
#include "lib/Semaphore.h"
|
||||||
|
|
||||||
class PreemptiveLoopThread : public Thread {
|
class PreemptiveLoopThread : public Thread {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
Semaphore* sem;
|
Semaphore* sem;
|
||||||
@ -21,4 +20,17 @@ public:
|
|||||||
void run() override;
|
void run() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PreemptiveThreadDemo : public Thread {
|
||||||
|
private:
|
||||||
|
PreemptiveThreadDemo(const PreemptiveThreadDemo& copy) = delete; // Verhindere Kopieren
|
||||||
|
|
||||||
|
public:
|
||||||
|
PreemptiveThreadDemo() {
|
||||||
|
kout << "Initialized PreemptiveThreadDemo" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thread-Startmethode
|
||||||
|
void run() override;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user