summaryrefslogtreecommitdiff
path: root/regress/lib/libpthread
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-08-04 21:55:23 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-08-04 21:55:23 +0000
commit210d7ea72ba678aaf8646ee99b234653db3813a4 (patch)
treeef3df9e159e2f07b82354500accb19a76ec608b4 /regress/lib/libpthread
parente5c22bf176d86e57aad598e0fcd674b277f4e49d (diff)
Add a test for caching of stacks with the default attributes
Diffstat (limited to 'regress/lib/libpthread')
-rw-r--r--regress/lib/libpthread/stack/stack.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/regress/lib/libpthread/stack/stack.c b/regress/lib/libpthread/stack/stack.c
index e11d512f1fb..32435b95800 100644
--- a/regress/lib/libpthread/stack/stack.c
+++ b/regress/lib/libpthread/stack/stack.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stack.c,v 1.2 2012/02/19 06:49:26 guenther Exp $ */
+/* $OpenBSD: stack.c,v 1.3 2012/08/04 21:55:22 guenther Exp $ */
/* PUBLIC DOMAIN Feb 2012 <guenther@openbsd.org> */
/* Test the handling of the pthread_attr_t stack attributes */
@@ -16,6 +16,15 @@
#define LARGE_SIZE (1024 * 1024)
+/* thread main for plain location tests */
+void *
+tmain0(void *arg)
+{
+ int s;
+
+ return (&s);
+}
+
/* thread main for testing a large buffer on the stack */
void *
tmain1(void *arg)
@@ -85,6 +94,26 @@ main(void)
ASSERT(size2 == size);
+ /* create a thread with the default stack attr so we can test reuse */
+ CHECKr(pthread_create(&t, NULL, &tmain0, NULL));
+ sleep(1);
+ CHECKr(pthread_join(t, &addr));
+
+ /*
+ * verify that the stack has *not* been freed: we expect it to be
+ * cached for reuse. This is unportable for the same reasons as
+ * the mquery() test below. :-/
+ */
+ *(int *)addr = 100;
+
+
+ /* do the above again and make sure the stack got reused */
+ CHECKr(pthread_create(&t, NULL, &tmain0, NULL));
+ sleep(1);
+ CHECKr(pthread_join(t, &addr2));
+ ASSERT(addr == addr2);
+
+
/*
* increase the stacksize, then verify that the change sticks,
* and that a large buffer fits on the resulting thread's stack