1 | #include <pthread.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <unistd.h> |
5 | |
6 | long my_global_variable; // global variable |
7 | |
8 | void *f1(void *p) { |
9 | my_global_variable = 42; |
10 | return NULL; |
11 | } |
12 | |
13 | void *f2(void *p) { |
14 | my_global_variable = 43; |
15 | return NULL; |
16 | } |
17 | |
18 | int main (int argc, char const *argv[]) |
19 | { |
20 | pthread_t t1; |
21 | pthread_create(newthread: &t1, NULL, start_routine: f1, NULL); |
22 | |
23 | pthread_t t2; |
24 | pthread_create(newthread: &t2, NULL, start_routine: f2, NULL); |
25 | |
26 | pthread_join(th: t1, NULL); |
27 | pthread_join(th: t2, NULL); |
28 | |
29 | return 0; |
30 | } |
31 |