-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththread.c
70 lines (57 loc) · 1.2 KB
/
thread.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* cc thread.c -lpthread Except.o Assert.o Lifo.o Hash.o List.o
*/
#include <pthread.h>
#include "Except.h"
#define NUM_THREADS 10
#define NUM_LAUNCHERS 10
void *launch(void *);
void *thread(void *);
int main(void)
{
pthread_t launchers[NUM_LAUNCHERS];
int i;
try
{
for (i = 0; i < NUM_LAUNCHERS; i++)
{
pthread_create(&launchers[i], NULL, launch, (void *)0);
}
for (i = 0; i < NUM_LAUNCHERS; i++)
{
pthread_join(launchers[i], NULL);
}
}
catch(Throwable, e)
{
e->printTryTrace(0);
}
finally;
}
void *launch(void *arg)
{
pthread_t threads[NUM_THREADS];
int i;
for (i = 0; i < NUM_THREADS; i++)
{
pthread_create(&threads[i], NULL, thread, (void *)0);
}
for (i = 0; i < NUM_THREADS; i++)
{
pthread_join(threads[i], NULL);
}
printf("launch: reporting that all %d threads have terminated\n", i);
return 0;
}
void *thread(void *arg)
{
try
{
*((int *)0) = 0; /* most probably causes runtime exception */
}
catch (RuntimeException, e)
{
e->printTryTrace(0);
}
finally;
}