-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest12.cpp
More file actions
executable file
·69 lines (56 loc) · 1.1 KB
/
test12.cpp
File metadata and controls
executable file
·69 lines (56 loc) · 1.1 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
//Join deadlock
#include <iostream>
#include <cstdlib>
#include "thread.h"
using std::cout;
using std::endl;
mutex print;
int count = 4;
void child1(void *arg);
void child2(void *arg);
void parent(void *arg);
void child1(void *arg){
thread th2(child2, (void *) arg);
while (count != 0){
th2.join();
print.lock();
cout << "child1 running" << endl;
print.unlock();
count--;
}
print.lock();
cout << "child1 call signal" << endl;
print.unlock();
print.lock();
print.lock();
cout << "CHILD1 finishes\n";
print.unlock();
}
void child2(void *arg){
while (count != 0){
((thread *)arg)->join();
print.lock();
cout << "child2 running" << endl;
print.unlock();
count--;
}
print.lock();
cout << "child2 call signal" << endl;
print.unlock();
print.lock();
cout << "CHILD2 finishes\n";
print.unlock();
}
void parent(void *arg){
print.lock();
cout << "PARENT running\n";
print.unlock();
thread th1(child1, (void *) &th1);
th1.join();
print.lock();
cout << "PARENT finishes\n";
print.unlock();
}
int main(){
cpu::boot(1, (thread_startfunc_t) parent, (void *) 10, false, false, 1);
}