diff --git a/c_os/user/CoopThreadDemo.cc b/c_os/user/CoopThreadDemo.cc index 7cbc0a7..ddce042 100644 --- a/c_os/user/CoopThreadDemo.cc +++ b/c_os/user/CoopThreadDemo.cc @@ -8,19 +8,40 @@ * Autor: Michael Schoettner, HHU, 21.8.2016 * *****************************************************************************/ -#include "kernel/Globals.h" #include "user/CoopThreadDemo.h" +#include "kernel/Globals.h" #include "user/LoopThread.h" - /***************************************************************************** * Methode: CoopThreadDemo::run * *---------------------------------------------------------------------------* * Beschreibung: Der Anwendungsthread erzeugt drei Threads die Zaehler * * ausgeben und terminiert sich selbst. * *****************************************************************************/ -void CoopThreadDemo::run () { - +void CoopThreadDemo::run() { + /* Hier muss Code eingefuegt werden */ - + + kout << "Allocating LoopThread A" << endl; + Thread* cntA = new LoopThread(0); + kout << "Allocating LoopThread B" << endl; + Thread* cntB = new LoopThread(1); + kout << "Allocating LoopThread C" << endl; + Thread* cntC = new LoopThread(2); + + kout << "Adding threads to ready queue" << endl; + scheduler.ready(cntA); + scheduler.ready(cntB); + scheduler.ready(cntC); + + int cnt = 0; + while (cnt++ < 1000) { + scheduler.yield(); + } + + kout << "Killing LoopThread A" << endl; + scheduler.kill(cntA); + + kout << "Exiting main thread" << endl; + scheduler.exit(); } diff --git a/c_os/user/CoopThreadDemo.h b/c_os/user/CoopThreadDemo.h index 91c4f2a..85f1c6a 100644 --- a/c_os/user/CoopThreadDemo.h +++ b/c_os/user/CoopThreadDemo.h @@ -10,22 +10,22 @@ #ifndef __coopthreaddemo_include__ #define __coopthreaddemo_include__ - +#include "kernel/Globals.h" #include "kernel/threads/Thread.h" - class CoopThreadDemo : public Thread { - + private: - CoopThreadDemo (const CoopThreadDemo ©); // Verhindere Kopieren + CoopThreadDemo(const CoopThreadDemo& copy) = delete; // Verhindere Kopieren public: // Gib dem Anwendungsthread einen Stack. - CoopThreadDemo () : Thread () { } + CoopThreadDemo() { + kout << "Initialized CoopThreadDemo" << endl; + } // Thread-Startmethode - void run (); - - }; + void run() override; +}; #endif diff --git a/c_os/user/LoopThread.cc b/c_os/user/LoopThread.cc index dcdc9ac..9fcc61f 100644 --- a/c_os/user/LoopThread.cc +++ b/c_os/user/LoopThread.cc @@ -9,14 +9,19 @@ #include "user/LoopThread.h" #include "kernel/Globals.h" - /***************************************************************************** * Methode: LoopThread::run * *---------------------------------------------------------------------------* * Beschreibung: Code des Threads. * *****************************************************************************/ -void LoopThread::run () { - - /* Hier muss Code eingefuegt werden */ - +void LoopThread::run() { + + /* Hier muss Code eingefuegt werden */ + + int cnt = 0; + while (true) { + kout.setpos(55, this->id); + kout << this->id << ": " << dec << cnt++ << endl; + scheduler.yield(); + } } diff --git a/c_os/user/LoopThread.h b/c_os/user/LoopThread.h index 47e9ec1..806cb33 100644 --- a/c_os/user/LoopThread.h +++ b/c_os/user/LoopThread.h @@ -12,18 +12,18 @@ #include "kernel/threads/Thread.h" class LoopThread : public Thread { - + private: int id; - LoopThread (const LoopThread ©); // Verhindere Kopieren - + LoopThread(const LoopThread& copy) = delete; // Verhindere Kopieren + public: // Gibt der Loop einen Stack und eine Id. - LoopThread (int i) : Thread () { id = i; } + LoopThread(int i) : id(i) {} // Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus. - void run (); + void run() override; }; #endif