brintos

brintos / llvm-project-archived public Read only

0
0
Text · 500 B · 7c9fee2 Raw
31 lines · cpp
1#include <pthread.h>2#include <stdio.h>3#include <stdlib.h>4#include <unistd.h>5 6long my_global_variable;  // global variable7 8void *f1(void *p) {9    my_global_variable = 42;10    return NULL;11}12 13void *f2(void *p) {14    my_global_variable = 43;15    return NULL;16}17 18int 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