• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // commit: 1a9a2ff7b0daf99100db53440a0b18b2801566ca 2011-02-13
2 // pthread_exit should call cancelation handlers
3 #include <pthread.h>
4 #include <string.h>
5 #include "test.h"
6 
7 #define TEST(r, f) if (((r)=(f))) t_error(#f " failed: %s\n", strerror(r))
8 
cleanup(void * arg)9 static void cleanup(void *arg)
10 {
11 	*(int *)arg = 1;
12 }
13 
start(void * arg)14 static void *start(void *arg)
15 {
16 	pthread_cleanup_push(cleanup, arg);
17 	pthread_exit(0);
18 	pthread_cleanup_pop(0);
19 	return arg;
20 }
21 
main(void)22 int main(void)
23 {
24 	pthread_t td;
25 	void *status;
26 	int arg = 0;
27 	int r;
28 
29 	TEST(r, pthread_create(&td, 0, start, &arg));
30 	TEST(r, pthread_join(td, &status));
31 	if (status)
32 		t_error("expected 0 thread exit status, got 0x%lx\n", (long)status);
33 	if (arg != 1)
34 		t_error("cleanup handler failed to run\n");
35 	return t_status;
36 }
37