1 //===-- main.cpp ------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 #include <pthread.h> 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <unistd.h> 12 13 long my_global_variable; // global variable 14 15 void *f1(void *p) { 16 my_global_variable = 42; 17 return NULL; 18 } 19 20 void *f2(void *p) { 21 my_global_variable = 43; 22 return NULL; 23 } 24 25 int main (int argc, char const *argv[]) 26 { 27 pthread_t t1; 28 pthread_create(&t1, NULL, f1, NULL); 29 30 pthread_t t2; 31 pthread_create(&t2, NULL, f2, NULL); 32 33 pthread_join(t1, NULL); 34 pthread_join(t2, NULL); 35 36 return 0; 37 } 38