-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExerc1.cpp
69 lines (37 loc) · 847 Bytes
/
Exerc1.cpp
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
#include <iostream>
#include <pthread.h>
using namespace std;
int vetor[14] = {33,5676,234,4567,243,7567,238,434,11,443,572,553,233,775};
int g1, g2;
pthread_t thread1, thread2;
void *greater1(void *Arg){
g1= vetor[0];
for (int i=0; i<7; i++){
if (vetor[i]>g1){
g1=vetor[i];
}
}
return 0;
}
void *greater2(void *Arg){
g2= vetor[7];
for (int i=7; i<14; i++){
if (vetor[i] > g2){
g2 = vetor[i];
}
}
return 0;
}
int main (){
pthread_create(&thread1, NULL, greater1, NULL);
pthread_create(&thread2, NULL, greater2, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
if (g1>g2){
cout<<"Greater: "<<g1<<endl;
}
else{
cout<<"Greater: "<<g2<<endl;
}
return 0;
}