(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / Examples / ex1.c
blob29138cf76176fd9a4e2ef1d3f2fc2752847263ab
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 static void *
11 process (void *arg)
13 int i;
14 fprintf (stderr, "Starting process %s\n", (char *) arg);
15 for (i = 0; i < 10000; i++)
17 write (1, (char *) arg, 1);
19 return NULL;
22 int
23 main (void)
25 int retcode;
26 pthread_t th_a, th_b;
27 void *retval;
29 retcode = pthread_create (&th_a, NULL, process, (void *) "a");
30 if (retcode != 0)
31 fprintf (stderr, "create a failed %d\n", retcode);
32 retcode = pthread_create (&th_b, NULL, process, (void *) "b");
33 if (retcode != 0)
34 fprintf (stderr, "create b failed %d\n", retcode);
35 retcode = pthread_join (th_a, &retval);
36 if (retcode != 0)
37 fprintf (stderr, "join a failed %d\n", retcode);
38 retcode = pthread_join (th_b, &retval);
39 if (retcode != 0)
40 fprintf (stderr, "join b failed %d\n", retcode);
41 return 0;