9 static pthread_mutex_t synch
= PTHREAD_MUTEX_INITIALIZER
;
12 test_thread (void *v_param
)
14 pthread_mutex_lock (&synch
);
18 #define STACKSIZE 0x100000
29 pthread_attr_init (&attr
);
30 stack
= mmap (NULL
, STACKSIZE
,
31 PROT_READ
| PROT_WRITE
| PROT_EXEC
,
32 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
34 if (stack
== MAP_FAILED
)
36 perror ("mmap failed");
40 status
= pthread_attr_setstack (&attr
, stack
, STACKSIZE
);
43 printf ("pthread_attr_setstack failed: %s\n", strerror (status
));
47 status
= pthread_attr_getstack (&attr
, &stack2
, &stacksize
);
50 printf ("pthread_attr_getstack failed: %s\n", strerror (status
));
54 if (stack2
!= stack
|| stacksize
!= STACKSIZE
)
56 printf ("first pthread_attr_getstack returned different stack (%p,%zx)\n"
57 "than was set by setstack (%p,%x)\n",
58 stack2
, stacksize
, stack
, STACKSIZE
);
62 status
= pthread_mutex_lock (&synch
);
65 printf ("cannot get lock: %s\n", strerror (status
));
69 status
= pthread_create (&thread
, &attr
, test_thread
, NULL
);
72 printf ("pthread_create failed: %s\n", strerror (status
));
76 status
= pthread_getattr_np (thread
, &attr
);
79 printf ("pthread_getattr_np failed: %s\n", strerror (status
));
83 status
= pthread_attr_getstack (&attr
, &stack2
, &stacksize
);
86 printf ("pthread_attr_getstack failed: %s\n", strerror (status
));
90 if (stack2
!= stack
|| stacksize
!= STACKSIZE
)
92 printf ("second pthread_attr_getstack returned different stack (%p,%zx)\n"
93 "than was set by setstack (%p,%x)\n",
94 stack2
, stacksize
, stack
, STACKSIZE
);
98 status
= pthread_mutex_unlock (&synch
);
101 printf ("cannot release lock: %s\n", strerror (status
));
105 /* pthread_detach (thread); */
106 if (pthread_join (thread
, NULL
) != 0)
108 printf ("join failed\n");