-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen-core.c
56 lines (47 loc) · 896 Bytes
/
gen-core.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 <pthread.h>
#include <unistd.h>
struct thread_info
{
int thread_num;
void *stack_var_addr;
void *fn_addr;
};
void *
thread_fn_1(void *arg)
{
struct thread_info *ti = arg;
int stack_var;
stack_var = ti->thread_num;
ti->stack_var_addr = &stack_var;
ti->fn_addr = thread_fn_1;
sleep(60);
return(NULL);
}
void *
thread_fn_2(void *arg)
{
struct thread_info *ti = arg;
float stack_var;
stack_var = ti->thread_num;
ti->stack_var_addr = &stack_var;
ti->fn_addr = thread_fn_2;
usleep(100000);
abort();
}
#define NUM_THREADS 3
struct thread_info info[NUM_THREADS];
pthread_t thread[NUM_THREADS];
int
main(int argc, char *argv[])
{
int i;
for (i = 0; i < NUM_THREADS; i++) {
info[i].thread_num = i;
pthread_create(&thread[i], NULL,
i < NUM_THREADS - 1 ? thread_fn_1 : thread_fn_2, &info[i]);
}
sleep(60);
return(0);
}