]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-exit3.c
Add per-thread cache to malloc
[thirdparty/glibc.git] / nptl / tst-exit3.c
CommitLineData
ed2ced8a
UD
1#include <pthread.h>
2#include <signal.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <unistd.h>
7
7e625f7e
FW
8static int do_test (void);
9
10#define TEST_FUNCTION do_test ()
11#include "../test-skeleton.c"
ed2ced8a
UD
12
13static pthread_barrier_t b;
14
15
16static void *
17tf2 (void *arg)
18{
19 while (1)
20 sleep (100);
21
22 /* NOTREACHED */
23 return NULL;
24}
25
26
27static void *
28tf (void *arg)
29{
30 pthread_t th;
31
32 int e = pthread_barrier_wait (&b);
33 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
34 {
35 puts ("barrier_wait failed");
36 exit (1);
37 }
38
39 e = pthread_create (&th, NULL, tf2, NULL);
40 if (e != 0)
41 {
42 printf ("create failed: %s\n", strerror (e));
43 exit (1);
44 }
45
46 /* Terminate only this thread. */
47 return NULL;
48}
49
50
51static int
52do_test (void)
53{
54 pthread_t th;
55
56 if (pthread_barrier_init (&b, NULL, 2) != 0)
57 {
58 puts ("barrier_init failed");
59 exit (1);
60 }
61
62 int e = pthread_create (&th, NULL, tf, NULL);
63 if (e != 0)
64 {
65 printf ("create failed: %s\n", strerror (e));
66 exit (1);
67 }
68
69 e = pthread_barrier_wait (&b);
70 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
71 {
72 puts ("barrier_wait failed");
73 exit (1);
74 }
75
7e625f7e
FW
76 delayed_exit (3);
77
ed2ced8a
UD
78 /* Terminate only this thread. */
79 pthread_exit (NULL);
80
81 /* NOTREACHED */
82 return 1;
83}