-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparent.cc
More file actions
35 lines (28 loc) · 1008 Bytes
/
parent.cc
File metadata and controls
35 lines (28 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "parent.h"
#include "bank.h"
#include "printer.h"
#include "MPRNG.h"
static const unsigned int AMOUNT_LOWER_BOUND = 1;
static const unsigned int AMOUNT_UPPER_BOUND = 3;
Parent::Parent(Printer &prt, Bank &bank, unsigned int numStudents, unsigned int parentalDelay) :
printer(prt),
bank(bank),
numStudents(numStudents),
parentalDelay(parentalDelay) {
}
void Parent::main() {
printer.print(Printer::Parent, Start);
while (true) {
_Accept(~Parent) {
// allow the destructor to terminate the task
break;
} _Else {
yield(parentalDelay);
int id = generator(numStudents - 1); // select a random student
int amount = generator(AMOUNT_LOWER_BOUND, AMOUNT_UPPER_BOUND); // select a random dollar amount
printer.print(Printer::Parent, Deposit, id, amount);
bank.deposit(id, amount);
}
}
printer.print(Printer::Parent, Finished);
}