-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththreads01.c
56 lines (45 loc) · 974 Bytes
/
threads01.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <inttypes.h>
#include <ucontext.h>
#include <pthread.h>
#include <signal.h>
void signal_handler(int sig)
{
switch(sig)
{
case SIGTRAP: printf("Received a SIGTRAP\n");
while (1 == 1) ;
break;
case SIGILL : printf("Received a SIGILL\n");
break;
default : printf("Received an unexpected signal!\n");
break;
}
printf("Exiting from signal_handler...\n");
}
void* worker(void *in)
{
pthread_t my_id;
my_id = pthread_self();
while (1 == 1)
{
printf("I'm thread %lx\n", my_id);
sleep(1);
}
}
int main(void)
{
pthread_t t0;
pthread_t t1;
signal(SIGTRAP, signal_handler);
signal(SIGILL , signal_handler);
signal(SIGHUP , signal_handler);
pthread_create(&t0, NULL, worker, NULL);
pthread_create(&t1, NULL, worker, NULL);
pthread_join(t0, NULL);
pthread_join(t1, NULL);
exit(0);
}