]> git.ipfire.org Git - thirdparty/glibc.git/blob - linuxthreads/Examples/ex12.c
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / linuxthreads / Examples / ex12.c
1 /* Variant of ex6, but this time we use pthread_exit (). */
2 #include <errno.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <pthread.h>
6 #include <unistd.h>
7
8 static void *
9 __attribute__ ((noreturn))
10 test_thread (void *v_param)
11 {
12 pthread_exit (NULL);
13 }
14
15 int
16 main (void)
17 {
18 unsigned long count;
19
20 setvbuf (stdout, NULL, _IONBF, 0);
21
22 for (count = 0; count < 2000; ++count)
23 {
24 pthread_t thread;
25 int status;
26
27 status = pthread_create (&thread, NULL, test_thread, NULL);
28 if (status != 0)
29 {
30 printf ("status = %d, count = %lu: %s\n", status, count,
31 strerror (errno));
32 return 1;
33 }
34 else
35 {
36 printf ("count = %lu\n", count);
37 }
38 /* pthread_detach (thread); */
39 if (pthread_join (thread, NULL) != 0)
40 {
41 printf ("join failed, count %lu\n", count);
42 return 2;
43 }
44 usleep (10);
45 }
46 return 0;
47 }