1

synchronize with semaphore

This commit is contained in:
2022-07-11 15:37:45 +02:00
parent 66b3b914d0
commit 597b823ac3
3 changed files with 15 additions and 7 deletions

View File

@ -1,12 +1,18 @@
#include "user/PreemptiveThreadDemo.h"
#include "lib/Semaphore.h"
void PreemptiveThreadDemo::run() {
kout << "PreemptiveThreadDemo ====================================" << 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
kout << "Allocating LoopThread A" << endl;
Thread* cntA = new PreemptiveLoopThread(0);
Thread* cntA = new PreemptiveLoopThread(0, sem);
kout << "Allocating LoopThread B" << endl;
Thread* cntB = new PreemptiveLoopThread(1);
Thread* cntB = new PreemptiveLoopThread(1, sem);
kout << "Allocating LoopThread C" << endl;
Thread* cntC = new PreemptiveLoopThread(2);
Thread* cntC = new PreemptiveLoopThread(2, sem);
kout << "Adding threads to ready queue" << endl;
scheduler.ready(cntA);