1

implement loop demo

This commit is contained in:
churl
2022-06-15 21:31:29 +02:00
parent a3aa13d946
commit 1a5c701546
4 changed files with 49 additions and 23 deletions

View File

@ -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();
}

View File

@ -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 &copy); // 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

View File

@ -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();
}
}

View File

@ -12,18 +12,18 @@
#include "kernel/threads/Thread.h"
class LoopThread : public Thread {
private:
int id;
LoopThread (const LoopThread &copy); // 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