synchronize textheavy demos
This commit is contained in:
@ -9,6 +9,8 @@
|
|||||||
#include "user/demo/VBEdemo.h"
|
#include "user/demo/VBEdemo.h"
|
||||||
|
|
||||||
void print_demo_menu() {
|
void print_demo_menu() {
|
||||||
|
kout.lock();
|
||||||
|
kout.clear();
|
||||||
kout << "Demo Menu, press number to start, k to kill:\n"
|
kout << "Demo Menu, press number to start, k to kill:\n"
|
||||||
<< "1 - Text Demo\n"
|
<< "1 - Text Demo\n"
|
||||||
<< "2 - PCSPK Demo\n"
|
<< "2 - PCSPK Demo\n"
|
||||||
@ -18,10 +20,10 @@ void print_demo_menu() {
|
|||||||
<< "6 - Bluescreen Demo\n"
|
<< "6 - Bluescreen Demo\n"
|
||||||
<< "7 - Preemption Demo\n"
|
<< "7 - Preemption Demo\n"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
kout.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::run() {
|
void MainMenu::run() {
|
||||||
kout.clear();
|
|
||||||
print_demo_menu();
|
print_demo_menu();
|
||||||
|
|
||||||
char input = '\0';
|
char input = '\0';
|
||||||
@ -61,8 +63,6 @@ void MainMenu::run() {
|
|||||||
} else if (input == 'k') {
|
} else if (input == 'k') {
|
||||||
scheduler.kill(choosen_demo); // NOTE: If thread exits itself this will throw error
|
scheduler.kill(choosen_demo); // NOTE: If thread exits itself this will throw error
|
||||||
choosen_demo = NULL;
|
choosen_demo = NULL;
|
||||||
|
|
||||||
kout.clear();
|
|
||||||
print_demo_menu();
|
print_demo_menu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
#include "user/demo/HeapDemo.h"
|
#include "user/demo/HeapDemo.h"
|
||||||
|
|
||||||
void HeapDemo::run() {
|
void HeapDemo::run() {
|
||||||
|
kout.lock();
|
||||||
|
kout.clear();
|
||||||
kout << "HEAP_DEMO ===================================================================" << endl;
|
kout << "HEAP_DEMO ===================================================================" << endl;
|
||||||
|
|
||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
@ -70,6 +72,7 @@ void HeapDemo::run() {
|
|||||||
allocator.dump_free_memory();
|
allocator.dump_free_memory();
|
||||||
|
|
||||||
kout << "HEAP_DEMO END ===============================================================" << endl;
|
kout << "HEAP_DEMO END ===============================================================" << endl;
|
||||||
|
kout.unlock();
|
||||||
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,29 +5,24 @@ void PreemptiveLoopThread::run() {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Basic synchronization by semaphore
|
// Basic synchronization by semaphore
|
||||||
sem->p();
|
// 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
|
||||||
|
kout.lock();
|
||||||
|
|
||||||
// Saving + restoring kout position doesn't help much as preemption still occurs,
|
// Saving + restoring kout position doesn't help much as preemption still occurs
|
||||||
// only LoopThreads are synchronized, so other output will be disturbed sometimes
|
|
||||||
kout.setpos(55, this->id);
|
kout.setpos(55, this->id);
|
||||||
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
||||||
|
|
||||||
sem->v();
|
kout.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreemptiveThreadDemo::run() {
|
void PreemptiveThreadDemo::run() {
|
||||||
kout << "Preemptive Thread Demo" << endl;
|
kout << "Preemptive Thread Demo" << endl;
|
||||||
kout << "Initializing Semaphore" << endl;
|
|
||||||
Semaphore* sem = new Semaphore(1); // Create this semaphore on the heap as this thread exits itself,
|
|
||||||
// so stack allocated objects will be lost
|
|
||||||
|
|
||||||
// TODO: Threads disappear, the fewer loop the faster they vanish
|
|
||||||
// It seems like this happens with exactly 3 or 4 loopthreads
|
|
||||||
Thread* threads[this->number_of_threads];
|
Thread* threads[this->number_of_threads];
|
||||||
kout << "Allocating LoopThreads" << endl;
|
kout << "Allocating LoopThreads" << endl;
|
||||||
for (unsigned int i = 0; i < this->number_of_threads; ++i) {
|
for (unsigned int i = 0; i < this->number_of_threads; ++i) {
|
||||||
threads[i] = new PreemptiveLoopThread(i, sem);
|
threads[i] = new PreemptiveLoopThread(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
kout << "Adding threads to ready queue" << endl;
|
kout << "Adding threads to ready queue" << endl;
|
||||||
|
|||||||
@ -8,13 +8,13 @@
|
|||||||
class PreemptiveLoopThread : public Thread {
|
class PreemptiveLoopThread : public Thread {
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
Semaphore* sem;
|
// Semaphore* sem;
|
||||||
|
|
||||||
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
|
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Gibt der Loop einen Stack und eine Id.
|
// Gibt der Loop einen Stack und eine Id.
|
||||||
PreemptiveLoopThread(int i, Semaphore* sem) : id(i), sem(sem) {}
|
PreemptiveLoopThread(int i) : id(i) {}
|
||||||
|
|
||||||
// Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus.
|
// Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus.
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|||||||
@ -14,7 +14,10 @@ void TextDemo::run() {
|
|||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
kout << "TextDemo\n" << endl;
|
kout.lock();
|
||||||
|
kout.clear();
|
||||||
|
kout << "TextDemo\n"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
kout << "Attribut (GREEN on WHITE): "
|
kout << "Attribut (GREEN on WHITE): "
|
||||||
<< white_b << green_f << "GREEN on WHITE" << endl
|
<< white_b << green_f << "GREEN on WHITE" << endl
|
||||||
@ -34,6 +37,7 @@ void TextDemo::run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kout << endl;
|
kout << endl;
|
||||||
|
kout.unlock();
|
||||||
|
|
||||||
scheduler.exit();
|
scheduler.exit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user