Remove unused localedata/th_TH.in
[glibc.git] / sysdeps / pthread / tst-tsd6.c
blob5f2aa42e986316858e1ab278d2515a25661be6e0
1 #include <errno.h>
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <sys/wait.h>
8 #define NKEYS 100
9 static pthread_key_t keys[NKEYS];
10 static pthread_barrier_t b;
13 static void *
14 tf (void *arg)
16 void *res = NULL;
17 for (int i = 0; i < NKEYS; ++i)
19 void *p = pthread_getspecific (keys[i]);
20 /* Use an arbitrary but valid pointer as the value. */
21 pthread_setspecific (keys[i], (void *) keys);
22 if (p != NULL)
23 res = p;
25 if (arg != NULL)
27 pthread_barrier_wait (arg);
28 pthread_barrier_wait (arg);
30 return res;
34 static int
35 do_test (void)
37 pthread_barrier_init (&b, NULL, 2);
39 for (int i = 0; i < NKEYS; ++i)
40 if (pthread_key_create (&keys[i], NULL) != 0)
42 puts ("cannot create keys");
43 return 1;
46 pthread_t th;
47 if (pthread_create (&th, NULL, tf, &b) != 0)
49 puts ("cannot create thread in parent");
50 return 1;
53 pthread_barrier_wait (&b);
55 pid_t pid = fork ();
56 if (pid == 0)
58 if (pthread_create (&th, NULL, tf, NULL) != 0)
60 puts ("cannot create thread in child");
61 exit (1);
64 void *res;
65 pthread_join (th, &res);
67 exit (res != NULL);
69 else if (pid == -1)
71 puts ("cannot create child process");
72 return 1;
75 int s;
76 if (TEMP_FAILURE_RETRY (waitpid (pid, &s, 0)) != pid)
78 puts ("failing to wait for child process");
79 return 1;
82 pthread_barrier_wait (&b);
83 pthread_join (th, NULL);
85 return !WIFEXITED (s) ? 2 : WEXITSTATUS (s);
89 #define TEST_FUNCTION do_test ()
90 #include "../test-skeleton.c"