-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
108 lines (89 loc) · 1.9 KB
/
Copy pathtest.cpp
File metadata and controls
108 lines (89 loc) · 1.9 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "gtthreads.h"
#include <iostream>
#include <stdlib.h>
#include <iostream>
#include <unistd.h>
#include <stdio.h>
using namespace std;
gtthread_mutex_t lock1;
void* thread_func1(void* arg)
{
int *p = (int*)arg;
cout << "Argument = " << *p << endl;
int i=0;
// gtthread_mutex_lock(&lock1);
while(i<5)
{
i++;
// if(i == 3)
// gtthread_cancel(3);
cout << "Called 1" << endl;
sleep(1);
}
// gtthread_mutex_unlock(&lock1);
int ret = *(int*)arg;
// gtthread_exit(&ret);
}
void* thread_func3(void* arg)
{
//cout <<
int i = 0;
// gtthread_mutex_lock(&lock1);
while(i<9)
{
i++;
cout << "Called 3" << endl;
// if(i == 5)
// gtthread_yield();
sleep(1);
}
// gtthread_mutex_unlock(&lock1);
int ret = *(int*)arg;
gtthread_exit(&ret);
}
void* thread_func2(void* arg)
{
int ret = *(int*)arg;
gtthread_exit(&ret);
// while(1)
// cout << "Called 3" << endl;
}
int main()
{
gtthread_mutex_init(&lock1);
gtthread_init(3000);
gtthread_t t1, t2, t3, t4;
int arg1 = 9;
int arg2 = 7;
int arg3 = 5;
int arg4 = 4;
int *status1 = new int();
int *status2 = new int();
int *status3 = new int();
int *status4 = new int();
gtthread_create(&t1, &thread_func1, (void*)&arg1);
gtthread_create(&t2, &thread_func2, (void*)&arg2);
gtthread_create(&t3, &thread_func3, (void*)&arg3);
gtthread_create(&t4, &thread_func2, (void*)&arg4);
cout << "Ret = " << gtthread_join(t2,(void**)&status1) << endl;
cout << "Ret = " << gtthread_join(t3,(void**)&status2) << endl;
cout << "Ret = " << gtthread_join(t1,(void**)&status3) << endl;;
cout << "Ret = " << gtthread_join(t4,(void**)&status4) << endl;
if(status3!=NULL)
{
cout << *status1 << endl;
cout << *status2 << endl;
cout << *status3 << endl;
cout << *status4 << endl;
}
//while(1);
int i=0;
/*while(i<7)
{
i++;
cout << "This is main" << endl;
sleep(1);
}*/
cout << "Main returning" << endl;
return 0;
}