• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
f1(void * p)8 void *f1(void *p) {
9     my_global_variable = 42;
10     return NULL;
11 }
12 
f2(void * p)13 void *f2(void *p) {
14     my_global_variable = 43;
15     return NULL;
16 }
17 
main(int argc,char const * argv[])18 int main (int argc, char const *argv[])
19 {
20     pthread_t t1;
21     pthread_create(&t1, NULL, f1, NULL);
22 
23     pthread_t t2;
24     pthread_create(&t2, NULL, f2, NULL);
25 
26     pthread_join(t1, NULL);
27     pthread_join(t2, NULL);
28 
29     return 0;
30 }
31