From 210d7ea72ba678aaf8646ee99b234653db3813a4 Mon Sep 17 00:00:00 2001 From: Philip Guenthe Date: Sat, 4 Aug 2012 21:55:23 +0000 Subject: Add a test for caching of stacks with the default attributes --- regress/lib/libpthread/stack/stack.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 */ /* 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 -- cgit v1.2.3