forked from RamkishanPOTHUGANTI/os_2_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemutilthread.cpp
More file actions
42 lines (33 loc) · 751 Bytes
/
Copy pathmemutilthread.cpp
File metadata and controls
42 lines (33 loc) · 751 Bytes
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
#include <iostream>
#include <thread>
#include "libmymem.hpp"
#include <unistd.h>
#include <time.h>
using namespace std;
int nthreads , iter ;
const int m = 1 , M = 8192;//rand()
void myThreadFun()
{
int n = iter;
for(int i = 0 ; i < n ; i++){
char * ptr = (char*)mymalloc(rand()%M + m);
ptr[0]='h';
ptr[1]='e';
ptr[2]='l';
usleep(rand()%10000);
myfree((void*)ptr);
}
return ;
}
int main(int argc, char const *argv[]) {
iter = atoi(argv[2]);
nthreads = atoi(argv[4]);
thread a[nthreads];
for (int i = 0; i < nthreads; i++) {
a[i] = std::thread(myThreadFun);
}
for (int i = 0; i < nthreads; i++) {
a[i].join();
}
return 0;
}