synchronize textheavy demos
This commit is contained in:
@ -9,6 +9,8 @@
|
||||
#include "user/demo/VBEdemo.h"
|
||||
|
||||
void print_demo_menu() {
|
||||
kout.lock();
|
||||
kout.clear();
|
||||
kout << "Demo Menu, press number to start, k to kill:\n"
|
||||
<< "1 - Text Demo\n"
|
||||
<< "2 - PCSPK Demo\n"
|
||||
@ -18,10 +20,10 @@ void print_demo_menu() {
|
||||
<< "6 - Bluescreen Demo\n"
|
||||
<< "7 - Preemption Demo\n"
|
||||
<< endl;
|
||||
kout.unlock();
|
||||
}
|
||||
|
||||
void MainMenu::run() {
|
||||
kout.clear();
|
||||
print_demo_menu();
|
||||
|
||||
char input = '\0';
|
||||
@ -61,8 +63,6 @@ void MainMenu::run() {
|
||||
} else if (input == 'k') {
|
||||
scheduler.kill(choosen_demo); // NOTE: If thread exits itself this will throw error
|
||||
choosen_demo = NULL;
|
||||
|
||||
kout.clear();
|
||||
print_demo_menu();
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "user/demo/HeapDemo.h"
|
||||
|
||||
void HeapDemo::run() {
|
||||
kout.lock();
|
||||
kout.clear();
|
||||
kout << "HEAP_DEMO ===================================================================" << endl;
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
@ -70,6 +72,7 @@ void HeapDemo::run() {
|
||||
allocator.dump_free_memory();
|
||||
|
||||
kout << "HEAP_DEMO END ===============================================================" << endl;
|
||||
kout.unlock();
|
||||
|
||||
scheduler.exit();
|
||||
}
|
||||
|
@ -5,29 +5,24 @@ void PreemptiveLoopThread::run() {
|
||||
|
||||
while (true) {
|
||||
// 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,
|
||||
// only LoopThreads are synchronized, so other output will be disturbed sometimes
|
||||
// Saving + restoring kout position doesn't help much as preemption still occurs
|
||||
kout.setpos(55, this->id);
|
||||
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
||||
|
||||
sem->v();
|
||||
kout.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void PreemptiveThreadDemo::run() {
|
||||
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];
|
||||
kout << "Allocating LoopThreads" << endl;
|
||||
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;
|
||||
|
@ -8,13 +8,13 @@
|
||||
class PreemptiveLoopThread : public Thread {
|
||||
private:
|
||||
int id;
|
||||
Semaphore* sem;
|
||||
// Semaphore* sem;
|
||||
|
||||
PreemptiveLoopThread(const PreemptiveLoopThread& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
// 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.
|
||||
void run() override;
|
||||
|
@ -14,7 +14,10 @@ void TextDemo::run() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
kout << "TextDemo\n" << endl;
|
||||
kout.lock();
|
||||
kout.clear();
|
||||
kout << "TextDemo\n"
|
||||
<< endl;
|
||||
|
||||
kout << "Attribut (GREEN on WHITE): "
|
||||
<< white_b << green_f << "GREEN on WHITE" << endl
|
||||
@ -34,6 +37,7 @@ void TextDemo::run() {
|
||||
}
|
||||
|
||||
kout << endl;
|
||||
kout.unlock();
|
||||
|
||||
scheduler.exit();
|
||||
}
|
||||
|
Reference in New Issue
Block a user