2 * Test program for verifying whether pthread cleanup handlers are invoked
14 static pthread_mutex_t s_mutex
;
17 static void cleanup_handler(void* param
)
19 fprintf(stderr
, "Cleanup handler has been called.\n");
20 pthread_mutex_unlock(&s_mutex
);
23 static void* f(void *p
)
25 if (pthread_mutex_lock(&s_mutex
) != 0)
27 fprintf(stderr
, "pthread_mutex_lock()\n");
31 pthread_cleanup_push(cleanup_handler
, NULL
);
33 pthread_cleanup_pop(true);
41 // Make sure the program exits in case a deadlock has been triggered.
44 if (pthread_mutex_init(&s_mutex
, NULL
) != 0)
46 fprintf(stderr
, "pthread_mutex_init()\n");
49 if (pthread_create(&pt1
, NULL
, f
, NULL
) != 0)
51 fprintf(stderr
, "pthread_create()\n");
54 if (pthread_create(&pt2
, NULL
, f
, NULL
) != 0)
56 fprintf(stderr
, "pthread_create()\n");
63 fprintf(stderr
, "Test succeeded.\n");