implement loop demo
This commit is contained in:
@ -8,19 +8,40 @@
|
|||||||
* Autor: Michael Schoettner, HHU, 21.8.2016 *
|
* Autor: Michael Schoettner, HHU, 21.8.2016 *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "kernel/Globals.h"
|
|
||||||
#include "user/CoopThreadDemo.h"
|
#include "user/CoopThreadDemo.h"
|
||||||
|
#include "kernel/Globals.h"
|
||||||
#include "user/LoopThread.h"
|
#include "user/LoopThread.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: CoopThreadDemo::run *
|
* Methode: CoopThreadDemo::run *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* Beschreibung: Der Anwendungsthread erzeugt drei Threads die Zaehler *
|
* Beschreibung: Der Anwendungsthread erzeugt drei Threads die Zaehler *
|
||||||
* ausgeben und terminiert sich selbst. *
|
* ausgeben und terminiert sich selbst. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void CoopThreadDemo::run () {
|
void CoopThreadDemo::run() {
|
||||||
|
|
||||||
/* Hier muss Code eingefuegt werden */
|
/* 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();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,22 +10,22 @@
|
|||||||
#ifndef __coopthreaddemo_include__
|
#ifndef __coopthreaddemo_include__
|
||||||
#define __coopthreaddemo_include__
|
#define __coopthreaddemo_include__
|
||||||
|
|
||||||
|
#include "kernel/Globals.h"
|
||||||
#include "kernel/threads/Thread.h"
|
#include "kernel/threads/Thread.h"
|
||||||
|
|
||||||
|
|
||||||
class CoopThreadDemo : public Thread {
|
class CoopThreadDemo : public Thread {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CoopThreadDemo (const CoopThreadDemo ©); // Verhindere Kopieren
|
CoopThreadDemo(const CoopThreadDemo& copy) = delete; // Verhindere Kopieren
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Gib dem Anwendungsthread einen Stack.
|
// Gib dem Anwendungsthread einen Stack.
|
||||||
CoopThreadDemo () : Thread () { }
|
CoopThreadDemo() {
|
||||||
|
kout << "Initialized CoopThreadDemo" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
// Thread-Startmethode
|
// Thread-Startmethode
|
||||||
void run ();
|
void run() override;
|
||||||
|
};
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -9,14 +9,19 @@
|
|||||||
#include "user/LoopThread.h"
|
#include "user/LoopThread.h"
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Methode: LoopThread::run *
|
* Methode: LoopThread::run *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* Beschreibung: Code des Threads. *
|
* Beschreibung: Code des Threads. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void LoopThread::run () {
|
void LoopThread::run() {
|
||||||
|
|
||||||
/* Hier muss Code eingefuegt werden */
|
/* Hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
|
while (true) {
|
||||||
|
kout.setpos(55, this->id);
|
||||||
|
kout << this->id << ": " << dec << cnt++ << endl;
|
||||||
|
scheduler.yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,18 +12,18 @@
|
|||||||
#include "kernel/threads/Thread.h"
|
#include "kernel/threads/Thread.h"
|
||||||
|
|
||||||
class LoopThread : public Thread {
|
class LoopThread : public Thread {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
LoopThread (const LoopThread ©); // Verhindere Kopieren
|
LoopThread(const LoopThread& copy) = delete; // Verhindere Kopieren
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Gibt der Loop einen Stack und eine Id.
|
// 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.
|
// Zaehlt einen Zaehler hoch und gibt ihn auf dem Bildschirm aus.
|
||||||
void run ();
|
void run() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user