/* * Implement 3 periodic threads, with periods 50ms, 100ms, and 150ms. * The job bodies are functions named task1(), task2() and task3() * (defined in cyclic_test.c) * * WARNING!!! This program is incomplete: it does not set the threads * priorities! (threads are scheduled using the SCHED_OTHER policy) */ #include #include #include #include #include #include #include "periodic_tasks.h" #include "cyclic_test.h" void *thread1(void *param) { struct periodic_task *p_d; p_d = start_periodic_timer(2000000, 50000); while (1) { wait_next_activation(p_d); task1(); } } void *thread2(void *param) { struct periodic_task *p_d; p_d = start_periodic_timer(2000000, 100000); while (1) { wait_next_activation(p_d); task2(); } } void *thread3(void *param) { struct periodic_task *p_d; p_d = start_periodic_timer(2000000, 150000); while (1) { wait_next_activation(p_d); task3(); } } int main(int argc, char *argv[]) { int err; void *returnvalue; pthread_t second_id, third_id, fourth_id; /* creation and activation of the new thread */ err = pthread_create(&second_id, NULL, thread1, (void *)NULL); if (err != 0) { fprintf(stderr, "Cannot create pthread 1"); } err = pthread_create(&third_id, NULL, thread2, (void *)NULL); if (err != 0) { fprintf(stderr, "Cannot create thread 2"); } err = pthread_create(&fourth_id, NULL, thread3, (void *)NULL); if (err != 0) { fprintf(stderr, "Cannot create thread 3"); } /* We wait the end of the threads we just created. */ pthread_join(second_id, &returnvalue); pthread_join(third_id, &returnvalue); pthread_join(fourth_id, &returnvalue); printf("main: returnvalue is %d\n", (int)returnvalue); return 0; }