diff --git a/MonitorExample/consumer.cpp b/MonitorExample/consumer.cpp index 55ca38f..528e052 100644 --- a/MonitorExample/consumer.cpp +++ b/MonitorExample/consumer.cpp @@ -12,6 +12,9 @@ template void Consumer::initClass(int numP, Monitor *m, void ( } //--------------------------------------- +//Semaphore with Number of Resources -> consume N Resources +//get spot of item in queue, take item, activate producers +//process item template void Consumer::run() { while (numProducts.tryAcquire()) { // While not all numProducts are consumed: T* aux = mon->canGet(); // Get pointer to item in itemQ diff --git a/MonitorExample/main.cpp b/MonitorExample/main.cpp index 722589c..e589af5 100644 --- a/MonitorExample/main.cpp +++ b/MonitorExample/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { c[i]->start(); } - + //make finished threads wait? for (int i = 0; i < N; i++) p[i]->wait(); for (int i = 0; i < M; i++) diff --git a/MonitorExample/monitor.cpp b/MonitorExample/monitor.cpp index 7d1cd74..b1ace5e 100644 --- a/MonitorExample/monitor.cpp +++ b/MonitorExample/monitor.cpp @@ -31,8 +31,8 @@ T* Monitor::canPut() { //consumer tries to take an item: // lock l -// push produced item to itemQ -// wake waiting consumer +// wait until items are in itemq +// take item template T* Monitor::canGet() { QMutexLocker ml(&l); // Lock entry controlling mutex l @@ -56,6 +56,10 @@ void Monitor::donePutting(T *x) { } //----------------------------------------- +//consumer is done with taking an item: +// lock l +// enlarge producer queue by one +// notify a producer of new spot template void Monitor::doneGetting(T *x) { QMutexLocker ml(&l); // Lock entry controlling mutex l diff --git a/MonitorExample/producer.cpp b/MonitorExample/producer.cpp index 427c4eb..4f49812 100644 --- a/MonitorExample/producer.cpp +++ b/MonitorExample/producer.cpp @@ -13,6 +13,9 @@ template void Producer::initClass(int numP, Monitor *m, T(*pro } //--------------------------------------- +//Semaphore with Number of Resources -> create N Resources +//produce item -> get spot in queue -> put item into second queue +//activate consumers template void Producer::run() { while (numProducts.tryAcquire()) { // While not all numProducts items are produced: