FreeBSD: add file descriptor tracking for _umtx_op
[valgrind.git] / none / tests / pth_self_kill.c
blob3ad675f256ca49cc8c8c1b0bcea7599932ff7d32
1 #include <signal.h>
2 #include <unistd.h>
3 #include <pthread.h>
4 #include <stdlib.h>
5 #include <stdio.h>
7 /* This reproduces bugs 409141 and 409367.
8 valgrind ./pth_self_kill 9 was hanging.
10 valgrind ./pth_self_kill 15 killotherthread was looping.
13 pthread_t parent_thr;
15 void *t(void *p)
17 sleep (200);
18 printf ("error: supposed to die without printing this\n");
19 exit (5);
20 return NULL;
23 void handler_15(int signum)
25 pthread_join(parent_thr, NULL);
26 exit(2);
29 int main(int argc, char **argv)
31 pthread_t thr;
33 parent_thr = pthread_self();
35 struct sigaction sa_old;
36 struct sigaction sa_new;
38 sigaction(15, NULL, &sa_old);
39 sa_new.sa_mask = sa_old.sa_mask;
40 sa_new.sa_flags = sa_old.sa_flags;
41 sa_new.sa_handler = &handler_15;
42 sigaction(15, &sa_new, NULL);
45 if (argc <= 1)
47 printf
48 ("usage: pth_self_kill SIGNALNR [killotherthread] [sleepafterkill]\n");
49 exit (1);
52 int s = atoi(argv[1]);
54 pthread_create(&thr, NULL, t, NULL);
55 sleep (1);
56 if (argc > 2)
58 pthread_kill(thr, s);
59 if (argc > 3)
60 sleep (2);
62 else
63 raise(s);
64 sigaction(15, &sa_old, NULL);