(res_isourserver): Fix cast.
[glibc/pb-stable.git] / linuxthreads / Examples / ex17.c
blobf5c99ee3fb5fdcba0ddc4b71d559024c27baa351
1 #include <errno.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <pthread.h>
5 #include <unistd.h>
6 #include <limits.h>
7 #include <sys/mman.h>
9 static void *
10 test_thread (void *v_param)
12 return NULL;
15 #define STACKSIZE 0x100000
17 int
18 main (void)
20 pthread_t thread;
21 pthread_attr_t attr;
22 int status;
23 void *stack, *stack2;
24 size_t stacksize;
26 pthread_attr_init (&attr);
27 stack = mmap (NULL, STACKSIZE,
28 PROT_READ | PROT_WRITE | PROT_EXEC,
29 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
31 if (stack == MAP_FAILED)
33 perror ("mmap failed");
34 return 1;
37 status = pthread_attr_setstack (&attr, stack, STACKSIZE);
38 if (status != 0)
40 printf ("pthread_attr_setstack failed: %s\n", strerror (status));
41 return 1;
44 status = pthread_attr_getstack (&attr, &stack2, &stacksize);
45 if (status != 0)
47 printf ("pthread_attr_getstack failed: %s\n", strerror (status));
48 return 1;
51 if (stack2 != stack || stacksize != STACKSIZE)
53 printf ("first pthread_attr_getstack returned different stack (%p,%x)\n"
54 "than was set by setstack (%p,%x)\n",
55 stack2, stacksize, stack, STACKSIZE);
56 return 2;
59 status = pthread_create (&thread, &attr, test_thread, NULL);
60 if (status != 0)
62 printf ("pthread_create failed: %s\n", strerror (status));
63 return 1;
66 status = pthread_getattr_np (thread, &attr);
67 if (status != 0)
69 printf ("pthread_getattr_np failed: %s\n", strerror (status));
70 return 1;
73 status = pthread_attr_getstack (&attr, &stack2, &stacksize);
74 if (status != 0)
76 printf ("pthread_attr_getstack failed: %s\n", strerror (status));
77 return 1;
80 if (stack2 != stack || stacksize != STACKSIZE)
82 printf ("second pthread_attr_getstack returned different stack (%p,%x)\n"
83 "than was set by setstack (%p,%x)\n",
84 stack2, stacksize, stack, STACKSIZE);
85 return 3;
88 /* pthread_detach (thread); */
89 if (pthread_join (thread, NULL) != 0)
91 printf ("join failed\n");
92 return 1;
94 return 0;