Blame src/regression/pthread_exit-cancel.c
|
Szabolcs Nagy |
cfa23c |
// commit: 1a9a2ff7b0daf99100db53440a0b18b2801566ca 2011-02-13
|
|
Szabolcs Nagy |
cfa23c |
// pthread_exit should call cancelation handlers
|
|
Szabolcs Nagy |
cfa23c |
#include <pthread.h>
|
|
Szabolcs Nagy |
cfa23c |
#include <string.h>
|
|
Szabolcs Nagy |
cfa23c |
#include "test.h"
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
#define TEST(r, f) if (((r)=(f))) t_error(#f " failed: %s\n", strerror(r))
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
static void cleanup(void *arg)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
*(int *)arg = 1;
|
|
Szabolcs Nagy |
cfa23c |
}
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
static void *start(void *arg)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
pthread_cleanup_push(cleanup, arg);
|
|
Szabolcs Nagy |
cfa23c |
pthread_exit(0);
|
|
Szabolcs Nagy |
cfa23c |
pthread_cleanup_pop(0);
|
|
Szabolcs Nagy |
cfa23c |
return arg;
|
|
Szabolcs Nagy |
cfa23c |
}
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
int main(void)
|
|
Szabolcs Nagy |
cfa23c |
{
|
|
Szabolcs Nagy |
cfa23c |
pthread_t td;
|
|
Szabolcs Nagy |
cfa23c |
void *status;
|
|
Szabolcs Nagy |
cfa23c |
int arg = 0;
|
|
Szabolcs Nagy |
cfa23c |
int r;
|
|
Szabolcs Nagy |
cfa23c |
|
|
Szabolcs Nagy |
cfa23c |
TEST(r, pthread_create(&td, 0, start, &arg));
|
|
Szabolcs Nagy |
cfa23c |
TEST(r, pthread_join(td, &status));
|
|
Szabolcs Nagy |
cfa23c |
if (status)
|
|
Szabolcs Nagy |
cfa23c |
t_error("expected 0 thread exit status, got 0x%lx\n", (long)status);
|
|
Szabolcs Nagy |
cfa23c |
if (arg != 1)
|
|
Szabolcs Nagy |
cfa23c |
t_error("cleanup handler failed to run\n");
|
|
Szabolcs Nagy |
cfa23c |
return t_status;
|
|
Szabolcs Nagy |
cfa23c |
}
|