From 8586535eb7343c5f563a7f0a19abd0b269fa2fcd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 8 Dec 2016 09:28:49 -0600 Subject: [PATCH] examples/ostest: Extend the pthread cancellation test to exercise pthread_cleanup_push() (and pthread_cleanup_pop() indirectly via pthread_cancel() and pthread_exit() --- examples/ostest/cancel.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/ostest/cancel.c b/examples/ostest/cancel.c index 73b214955..0aad378d5 100644 --- a/examples/ostest/cancel.c +++ b/examples/ostest/cancel.c @@ -33,19 +33,40 @@ * ****************************************************************************/ +#include + #include #include #include #include + #include "ostest.h" static pthread_mutex_t mutex; static pthread_cond_t cond; -static void *thread_waiter(void *parameter) +#ifdef CONFIG_PTHREAD_CLEANUP +static void thread_cleaner(FAR void *arg) +{ + printf("thread_cleaner #%u\n", (unsigned int)((uintptr_t)arg)); +} +#endif + +static FAR void *thread_waiter(FAR void *parameter) { int status; +#ifdef CONFIG_PTHREAD_CLEANUP + int i; + + /* Register some clean-up handlers */ + + for (i = 0; i < CONFIG_PTHREAD_CLEANUP_STACKSIZE ; i++) + { + pthread_cleanup_push(thread_cleaner, (FAR void *)((uintptr_t)(i+1))); + } +#endif + /* Take the mutex */ printf("thread_waiter: Taking mutex\n");