/* Nathan DeBardeleben - ndebard@parl.clemson.edu * ECE 329 * Test program for thread project. This is very simple * and the only real change over Dr. Ligon's test program is * that this one will call thread exit. You should find that * all 5 threads (main and 4 others) start up and then task1 * dies, then task3 and then task4. This will leave only * main and task2 alternating. */ #include int task1(); int task2(); int task3(); int task4(); int main(int argc, char **argv) { int i; if(thread_init() < 0) { fprintf(stderr,"Error initializing threads.\n"); exit(1); } if(thread_create(task1, 1) < 0) { fprintf(stderr,"Error starting task 1.\n"); exit(1); } if(thread_create(task2, 2) < 0) { fprintf(stderr,"Error starting task 2.\n"); exit(1); } if(thread_create(task3, 3) < 0) { fprintf(stderr,"Error starting task 3.\n"); exit(1); } if(thread_create(task4, 4) < 0) { fprintf(stderr,"Error starting task 4.\n"); exit(1); } while(1) { printf("MAIN THREAD\n"); for(i=0; i<5000000; i++) ; } thread_exit(); return 0; } int task1() { int i; for(i=0; i<2000; i++) printf("\t[%d] THREAD 1\n", i); thread_exit(); } int task2() { int i; while(1) printf("\t\tTHREAD 2\n"); thread_exit(); } int task3() { int i; for(i=0; i<3000; i++) printf("\t\t\t[%d] THREAD 3\n", i); thread_exit(); } int task4() { int i; for(i=0; i<4000; i++) printf("\t\t\t\t[%d] THREAD 4\n", i); thread_exit(); }