1 /* Creates two threads, one printing 10000 "a"s, the other printing
3 Illustrates: thread creation, thread joining. */
10 static void *process(void * arg)
13 printf("Starting process %s\n", (char *)arg);
14 for (i = 0; i < 10000; i++)
15 write(1, (char *) arg, 1);
19 #define sucfail(r) (r != 0 ? "failed" : "succeeded")
26 ret += (pret = pthread_create(&th_a, NULL, process, (void *)"a"));
27 printf("create a %s %d\n", sucfail(pret), pret);
28 ret += (pret = pthread_create(&th_b, NULL, process, (void *)"b"));
29 printf("create b %s %d\n", sucfail(pret), pret);
30 ret += (pret = pthread_join(th_a, &retval));
31 printf("join a %s %d\n", sucfail(pret), pret);
32 ret += (pret = pthread_join(th_b, &retval));
33 printf("join b %s %d\n", sucfail(pret), pret);