-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCase-AsyncIO.cpp
More file actions
86 lines (62 loc) · 1.78 KB
/
TestCase-AsyncIO.cpp
File metadata and controls
86 lines (62 loc) · 1.78 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
#include <iostream>
#include <ucontext.h>
#include <zconf.h>
#include "uthread.h"
#include <fcntl.h>
using namespace std;
void* t1(void *i){
cout << "Starting Thread 1" << endl;
cout << "Doing async I/O" << endl;
int file = open("test.txt", O_RDONLY, 0);
if (file == -1) {
cout << "Unable to open file!" << endl;
}
char* buffer = new char[1000];
async_read(file, (void* )buffer, 1000);
cout << "Printing File contents :- " << endl;
cout << buffer << endl;
delete[] buffer;
close(file);
cout << "Ending Thread 1" << endl;
}
void* t2(void *i){
cout << "Starting Thread 2" << endl;
for ( int i = 0 ; i < 10 ; i++ ){
for ( int j = 0 ; j < 10000 ; j++ ){ }
cout << "in T2" << endl;
}
cout << "Ending Thread 2" << endl;
}
void* t3(void *i){
cout << "Starting Thread 3" << endl;
for ( int i = 0 ; i < 10 ; i++ ){
for ( int j = 0 ; j < 10000 ; j++ ){ }
cout << "in T3" << endl;
}
cout << "Ending Thread 3" << endl;
}
int main() {
// Put Main TCB in sch_queue
int t1Arg = 1;
int t1PID;
void *ar1 = (void*)malloc(100);
void **t1RetVal = (void**)&ar1;
t1PID = uthread_create(t1, (void*)(&t1Arg));
int t2Arg = 2;
int t3Arg = 3;
int t2PID, t3PID;
void *ar2 = (void*)malloc(100);
void **t2RetVal = (void**)&ar2;
void *ar3 = (void*)malloc(100);
void **t3RetVal = (void**)&ar3;
t2PID = uthread_create(t2, (void*)(&t2Arg));
t3PID = uthread_create(t3, (void*)(&t3Arg));
uthread_join(t1PID,t1RetVal);
cout << "t1 check crossed" << endl;
uthread_join(t2PID,t1RetVal);
cout << "t2 check crossed" << endl;
uthread_join(t3PID,t1RetVal);
cout << "t3 check crossed" << endl;
cout << "Main done" << endl;
return 0;
}