1570af302Sopenharmony_ci// commit: 1a9a2ff7b0daf99100db53440a0b18b2801566ca 2011-02-13 2570af302Sopenharmony_ci// pthread_exit should call cancelation handlers 3570af302Sopenharmony_ci#include <pthread.h> 4570af302Sopenharmony_ci#include <string.h> 5570af302Sopenharmony_ci#include "test.h" 6570af302Sopenharmony_ci 7570af302Sopenharmony_ci#define TEST(r, f) if (((r)=(f))) t_error(#f " failed: %s\n", strerror(r)) 8570af302Sopenharmony_ci 9570af302Sopenharmony_cistatic void cleanup(void *arg) 10570af302Sopenharmony_ci{ 11570af302Sopenharmony_ci *(int *)arg = 1; 12570af302Sopenharmony_ci} 13570af302Sopenharmony_ci 14570af302Sopenharmony_cistatic void *start(void *arg) 15570af302Sopenharmony_ci{ 16570af302Sopenharmony_ci pthread_cleanup_push(cleanup, arg); 17570af302Sopenharmony_ci pthread_exit(0); 18570af302Sopenharmony_ci pthread_cleanup_pop(0); 19570af302Sopenharmony_ci return arg; 20570af302Sopenharmony_ci} 21570af302Sopenharmony_ci 22570af302Sopenharmony_ciint main(void) 23570af302Sopenharmony_ci{ 24570af302Sopenharmony_ci pthread_t td; 25570af302Sopenharmony_ci void *status; 26570af302Sopenharmony_ci int arg = 0; 27570af302Sopenharmony_ci int r; 28570af302Sopenharmony_ci 29570af302Sopenharmony_ci TEST(r, pthread_create(&td, 0, start, &arg)); 30570af302Sopenharmony_ci TEST(r, pthread_join(td, &status)); 31570af302Sopenharmony_ci if (status) 32570af302Sopenharmony_ci t_error("expected 0 thread exit status, got 0x%lx\n", (long)status); 33570af302Sopenharmony_ci if (arg != 1) 34570af302Sopenharmony_ci t_error("cleanup handler failed to run\n"); 35570af302Sopenharmony_ci return t_status; 36570af302Sopenharmony_ci} 37