Sync "language", "lang_name", "territory", "country_name" with CLDR/langtable
[glibc.git] / nptl / tst-basic7.c
blob29a2461efe8d19c31d00a4a925c27f84aa4134b5
1 #include <errno.h>
2 #include <limits.h>
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <sys/mman.h>
9 #include <sys/resource.h>
11 static void use_stack (size_t needed);
13 void (*use_stack_ptr) (size_t) = use_stack;
15 static void
16 use_stack (size_t needed)
18 size_t sz = sysconf (_SC_PAGESIZE);
19 char *buf = alloca (sz);
20 memset (buf, '\0', sz);
22 if (needed > sz)
23 use_stack_ptr (needed - sz);
26 static void
27 use_up_memory (void)
29 struct rlimit rl;
30 getrlimit (RLIMIT_AS, &rl);
31 rl.rlim_cur = 10 * 1024 * 1024;
32 setrlimit (RLIMIT_AS, &rl);
34 char *c;
35 int PAGESIZE = getpagesize ();
36 while (1)
38 c = mmap (NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
39 if (c == MAP_FAILED)
40 break;
44 static void *
45 child (void *arg)
47 sleep (1);
48 return arg;
51 static int
52 do_test (void)
54 int err;
55 pthread_t tid;
57 /* Allocate the memory needed for the stack. */
58 use_stack_ptr (PTHREAD_STACK_MIN);
60 use_up_memory ();
62 err = pthread_create (&tid, NULL, child, NULL);
63 if (err != 0)
65 printf ("pthread_create returns %d: %s\n", err,
66 err == EAGAIN ? "OK" : "FAIL");
67 return err != EAGAIN;
70 /* We did not fail to allocate memory despite the preparation. Oh well. */
71 return 0;
74 #define TEST_FUNCTION do_test ()
75 #include "../test-skeleton.c"