Update.
[glibc.git] / linuxthreads / Examples / ex1.c
blobf455ecfaf0c1ebd828a2fcc64457e6478f93ec40
1 /* Creates two threads, one printing 10000 "a"s, the other printing
2 10000 "b"s.
3 Illustrates: thread creation, thread joining. */
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <unistd.h>
8 #include "pthread.h"
10 void * process(void * arg)
12 int i;
13 fprintf(stderr, "Starting process %s\n", (char *) arg);
14 for (i = 0; i < 10000; i++) {
15 write(1, (char *) arg, 1);
17 return NULL;
20 int main(void)
22 int retcode;
23 pthread_t th_a, th_b;
24 void * retval;
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);
34 return 0;