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