-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest17.cpp
More file actions
executable file
·57 lines (43 loc) · 1.03 KB
/
test17.cpp
File metadata and controls
executable file
·57 lines (43 loc) · 1.03 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
#include <iostream>
#include <cstdlib>
#include "thread.h"
using std::cout;
using std::endl;
mutex printlock;
void child1(void *arg);
void child2(void *arg);
void parent(void *arg);
thread * thread_ptr;
void child1(void *arg){
printlock.lock();
cout << (char*)arg << " running\n";
printlock.unlock();
thread_ptr->join();
printlock.lock();
cout << (char*)arg << " finishes\n";
printlock.unlock();
}
void child2(void *arg){
printlock.lock();
cout << (char*)arg << " running\n";
printlock.unlock();
thread::yield();
printlock.lock();
cout << (char*)arg << " finishes\n";
printlock.unlock();
}
void parent(void *arg){
printlock.lock();
cout << (char*)arg << " running\n";
printlock.unlock();
thread_ptr = new thread(child2, (void *) "th0");
thread th1(child1, (void *) "th1");
thread th2(child1, (void *) "th2");
thread th3(child1, (void *) "th3");
printlock.lock();
cout << (char*)arg << " finish\n";
printlock.unlock();
}
int main(){
cpu::boot(1, (thread_startfunc_t) parent, (void *) "parent", false, false, 1);
}