/* * main.cpp * * Created on: Mar 3, 2015 * Author: student */ #include #include #include #include #include #include "ChildExampleThread.h" using namespace std; /** * This program will use interrupts to control an input device. It will turn an LED on and off * based on input transitions. */ int main(int argc, char* argv[]) { // Setup the thread for the blinking light and let it run. ChildExampleThread ct1; ChildExampleThread ct2; ChildExampleThread ct3; ChildExampleThread ct4; cout << "Max: " << sched_get_priority_max(SCHED_FIFO)<<"\n"; cout << "Min: " << sched_get_priority_min(SCHED_FIFO)<<"\n"; // Start each of the four threads up. pthread_attr_t firstThreadAttributes; struct sched_param fifo_param; pthread_attr_init(&firstThreadAttributes); pthread_attr_setinheritsched(&firstThreadAttributes, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&firstThreadAttributes, SCHED_FIFO); fifo_param.__sched_priority=1; pthread_attr_setschedparam(&firstThreadAttributes, &fifo_param); pthread_attr_t secondThreadAttributes; struct sched_param fifo_param2; pthread_attr_init(&secondThreadAttributes); pthread_attr_setinheritsched(&secondThreadAttributes, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&secondThreadAttributes, SCHED_FIFO); fifo_param2.__sched_priority=99; pthread_attr_setschedparam(&secondThreadAttributes, &fifo_param2); pthread_attr_t thirdThreadAttributes; struct sched_param fifo_param3; pthread_attr_init(&thirdThreadAttributes); pthread_attr_setinheritsched(&thirdThreadAttributes, PTHREAD_EXPLICIT_SCHED); pthread_attr_setschedpolicy(&thirdThreadAttributes, SCHED_FIFO); fifo_param2.__sched_priority=50; pthread_attr_setschedparam(&thirdThreadAttributes, &fifo_param3); ct1.start(&firstThreadAttributes); ct2.start(&secondThreadAttributes); ct3.start(&thirdThreadAttributes); // ct1.start(NULL); // ct2.start(NULL); // ct3.start(NULL); // ct4.start(NULL); // Block waiting for someone to do something. char text; cin >> text; // Stop the threads. ct1.stopThread(); ct2.stopThread(); ct3.stopThread(); //ct4.stopThread(); // Wait for the threads to die. pthread_join(ct1.getThread(), NULL); pthread_join(ct2.getThread(), NULL); pthread_join(ct3.getThread(), NULL); //pthread_join(ct4.getThread(), NULL); ct1.printResult(); ct2.printResult(); ct3.printResult(); //ct4.printResult(); }