1

add semaphore to cga_stream + use it in demos

This commit is contained in:
2022-07-22 18:12:56 +02:00
parent e3dcadcc3c
commit e56e76ea4e
14 changed files with 39 additions and 13 deletions

View File

@ -1,23 +1,22 @@
#include "user/demo/PreemptiveThreadDemo.h"
Semaphore PreemptiveLoopThread::sem(1);
void PreemptiveLoopThread::run() {
int cnt = 0;
while (true) {
// Basic synchronization by semaphore
sem.p();
kout.lock();
// 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.lock();
kout.clear();
kout << "Preemptive Thread Demo:" << endl;
@ -28,5 +27,6 @@ void PreemptiveThreadDemo::run() {
}
kout << "Exiting main thread" << endl;
kout.unlock();
scheduler.exit();
}