diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-12-22 20:10:10 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-12-22 20:10:10 +0000 |
commit | a334319f6530564d22e775935d9c91663623a1b4 (patch) | |
tree | b5877475619e4c938e98757d518bb1e9cbead751 /linuxthreads/Examples/ex7.c | |
parent | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff) | |
download | glibc-a334319f6530564d22e775935d9c91663623a1b4.tar glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.bz2 glibc-a334319f6530564d22e775935d9c91663623a1b4.zip |
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'linuxthreads/Examples/ex7.c')
-rw-r--r-- | linuxthreads/Examples/ex7.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/linuxthreads/Examples/ex7.c b/linuxthreads/Examples/ex7.c new file mode 100644 index 0000000000..d9db33c5cd --- /dev/null +++ b/linuxthreads/Examples/ex7.c @@ -0,0 +1,45 @@ +/* This is a test of the special shutdown that occurs + when all threads, including the main one, call + pthread_exit(). It demonstrates that atexit + handlers are properly called, and that the + output is properly flushed even when stdout is + redirected to a file, and therefore fully buffered. */ + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> + +#define NTHREADS 20 /* number of threads */ + +static void * +thread (void *arg) +{ + printf ("thread terminating\n"); + return 0; +} + +static void +cleanup (void) +{ + printf ("atexit handler called\n"); +} + +int +main (void) +{ + int i; + + atexit (cleanup); + + for (i = 0; i < NTHREADS; i++) + { + pthread_t id; + if (pthread_create (&id, 0, thread, 0) != 0) + { + fprintf (stderr, "pthread_create failed\n"); + abort (); + } + } + + pthread_exit (0); +} |