-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.c
More file actions
88 lines (69 loc) · 2.94 KB
/
test.c
File metadata and controls
88 lines (69 loc) · 2.94 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "pthread.h"
#include "threads.h"
thrd_t g1; // COMPLIANT
pthread_t g2; // COMPLIANT
void *pthread_func(void *arg);
void *pthread_func_inner(void *arg);
int thrd_func(void *arg);
int thrd_func_inner(void *arg);
void make_threads_called_from_main(void);
void func_called_from_main(void);
void make_threads_called_from_func_called_from_main(void);
void make_threads_called_from_main_pthread_thrd(void);
int main(int argc, char *argv[]) {
thrd_create(&g1, &thrd_func, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func, NULL); // COMPLIANT
thrd_create(&g1, &thrd_func_inner, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // COMPLIANT
make_threads_called_from_main();
func_called_from_main();
make_threads_called_from_main_pthread_thrd();
}
void make_threads_called_from_main() {
thrd_create(&g1, &thrd_func_inner, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // COMPLIANT
}
void func_called_from_main() {
make_threads_called_from_func_called_from_main();
}
void make_threads_called_from_func_called_from_main() {
thrd_create(&g1, &thrd_func_inner, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // COMPLIANT
}
void make_threads_called_from_pthread_func(void);
void make_threads_called_from_thrd_func(void);
void func_called_from_pthread_thrd(void);
void make_threads_called_from_func_called_from_pthread_thrd(void);
void *pthread_func(void *arg) {
thrd_create(&g1, &thrd_func_inner, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // NON-COMPLIANT
make_threads_called_from_pthread_func();
func_called_from_pthread_thrd();
make_threads_called_from_main_pthread_thrd();
}
int thrd_func(void *arg) {
thrd_create(&g1, &thrd_func_inner, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // NON-COMPLIANT
make_threads_called_from_thrd_func();
func_called_from_pthread_thrd();
make_threads_called_from_main_pthread_thrd();
}
void make_threads_called_from_thrd_func(void) {
thrd_create(&g1, &thrd_func_inner, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // NON-COMPLIANT
}
void func_called_from_pthread_thrd(void) {
make_threads_called_from_func_called_from_pthread_thrd();
}
void make_threads_called_from_func_called_from_pthread_thrd(void) {
thrd_create(&g1, &thrd_func_inner, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // NON-COMPLIANT
}
void make_threads_called_from_main_pthread_thrd() {
thrd_create(&g1, &thrd_func_inner, NULL); // NON-COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // NON-COMPLIANT
}
void make_threads_not_called_by_anyone() {
thrd_create(&g1, &thrd_func_inner, NULL); // COMPLIANT
pthread_create(&g2, NULL, &pthread_func_inner, NULL); // COMPLIANT
}