(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / Examples / ex7.c
blobd9db33c5cd8c4ceffe42a02e8e6604a7ea859b84
1 /* This is a test of the special shutdown that occurs
2 when all threads, including the main one, call
3 pthread_exit(). It demonstrates that atexit
4 handlers are properly called, and that the
5 output is properly flushed even when stdout is
6 redirected to a file, and therefore fully buffered. */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <pthread.h>
12 #define NTHREADS 20 /* number of threads */
14 static void *
15 thread (void *arg)
17 printf ("thread terminating\n");
18 return 0;
21 static void
22 cleanup (void)
24 printf ("atexit handler called\n");
27 int
28 main (void)
30 int i;
32 atexit (cleanup);
34 for (i = 0; i < NTHREADS; i++)
36 pthread_t id;
37 if (pthread_create (&id, 0, thread, 0) != 0)
39 fprintf (stderr, "pthread_create failed\n");
40 abort ();
44 pthread_exit (0);