/* * Copyright (C) 2014 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ /** * @ingroup tests * @{ * * @file * @brief pthread test application * * @author René Kijewski * * @} */ #include #include "pthread.h" #define RET_EXIT ((void *) 1234) #define RET_FAIL ((void *) 5678) static void cleanup(void *arg) { printf("Cleanup: <%s>\n", (const char *) arg); } static void *run(void *unused) { (void) unused; /* indentation for visibility */ puts(""); pthread_cleanup_push(cleanup, "1"); puts(""); pthread_cleanup_push(cleanup, "2"); puts(""); pthread_cleanup_push(cleanup, "3"); puts(""); pthread_cleanup_push(cleanup, "4"); puts(""); pthread_cleanup_push(cleanup, "5"); puts(""); pthread_cleanup_pop(1); puts(""); pthread_cleanup_pop(0); /* cleanup 4 should not be executed */ puts(""); pthread_cleanup_pop(1); pthread_exit(RET_EXIT); puts("/"); /* thread exited, should not be printed */ pthread_cleanup_pop(0); /* should be printed nevertheless */ puts(""); pthread_cleanup_pop(1); puts(""); return RET_FAIL; } int main(void) { puts("Start."); pthread_t th_id; pthread_create(&th_id, NULL, run, NULL); void *res; pthread_join(th_id, (void **) &res); printf("Result: %u\n", (int) (intptr_t) res); puts("Done."); return 0; }