/* ---------------------------------------------------------------- */ /* PROGRAM ex1.c */ /* This program creates two threads, each of which displays a */ /* number of integers. Note that the functions for these two */ /* threads are almost identical. Will you be able to combine */ /* these two functions, ThreadA() and ThreadB(), into a single */ /* function? */ /* ---------------------------------------------------------------- */ #include #include #define MAX_ITERATION 200 void *ThreadA(void *DontNeedIt) { int i; for (i = 1; i <= MAX_ITERATION; i++) printf("Thread A speaking: iteration %d\n", i); thr_exit(NULL); } void *ThreadB(void *DontNeedIt) { int i; for (i = 1; i <= MAX_ITERATION; i++) printf(" Thread B speaking: iteration %d\n", i); thr_exit(NULL); } void main(void) { thread_t FirstThread, SecondThread; size_t StatusFromA, StatusFromB; thr_create(NULL, 0, ThreadA, (void *) NULL, 0, &FirstThread); thr_create(NULL, 0, ThreadB, (void *) NULL, 0, &SecondThread); thr_join(FirstThread, 0, (void *) &StatusFromA); thr_join(SecondThread, 0, (void *) &StatusFromB); }