Listing 9: The Test Harness #include "calculator.hpp" #include "printer.hpp" #include #include calculator *calc = NULL; void * runPrinter(void *arg) { printer *prn = (printer *)arg; prn->printPowersOfTwo(calc); } void * runCalculator(void *arg) { calculator *calc = (calculator *)arg; calc->calcPowersOfTwo(); } void main() { thread_t prn1Tid, prn2Tid, prn3Tid, prn4Tid, calcTid; calc = new calculator(); thr_create(NULL, 0, runCalculator, calc, 0, &calcTid); printer *prn1 = new printer(); prn1->printerName = "First Printer"; thr_create(NULL, 0, runPrinter, prn1, 0, &prn1Tid); printer *prn2 = new printer(); prn2->printerName = "Second Printer"; thr_create(NULL, 0, runPrinter, prn2, 0, &prn2Tid); printer *prn3 = new printer(); prn3->printerName = "Third Printer"; thr_create(NULL, 0, runPrinter, prn3, 0, &prn3Tid); printer *prn4 = new printer(); prn4->printerName = "Fourth Printer"; thr_create(NULL, 0, runPrinter, prn4, 0, &prn4Tid); // Wait for the calculator thread to finish thr_join(calcTid, NULL, NULL); // Signal the printer threads thr_kill(prn1Tid, SIGUSR1); thr_kill(prn2Tid, SIGUSR1); thr_kill(prn3Tid, SIGUSR1); thr_kill(prn4Tid, SIGUSR1); // Wait for the printer threads to complete char wait; cin >> wait; }