-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.c
59 lines (50 loc) · 1.33 KB
/
debug.c
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
/*
* debug.c
*
* Created on: Oct 27, 2018
* Author: sg1425
*/
#include "my_pthread_t.h"
#include "my_mem_manager.h"
/*
int main(int argc, char **argv) {
int *i = malloc(500 * sizeof(int));
*i = malloc(100 * sizeof(int));
}
*/
void * dummyFunction(tcb *thread) {
my_pthread_t curr_threadID = thread->tid;
printf("Entered Thread %i\n", curr_threadID);
int i = 0, tot_mem = 0;
for (i = 0; i < 5; i++) {
tot_mem += 4000;
printf("Thread : %d total: %d\n", curr_threadID, tot_mem);
int *ptr = (int*)malloc(4000);
*ptr = curr_threadID * 100 + i;
printf("Store : %d\n", *ptr);
pthread_yield();
printf("Thread : %d Retrieve : %d\n", curr_threadID, *ptr);
}
printf("Exited Thread: %i\n", curr_threadID);
return &(thread->tid);
}
int main(int argc, char **argv) {
pthread_t t1, t2, t3, t4;
pthread_create(&t1, NULL, (void *) dummyFunction, &t1);
pthread_create(&t2, NULL, (void *) dummyFunction, &t2);
int curr_threadID = 1;
int i = 0, tot_mem = 0;
for (i = 0; i < 5; i++) {
tot_mem += 4000;
printf("Thread : %d total: %d\n", curr_threadID, tot_mem);
int *ptr = (int*)malloc(3000);
*ptr = curr_threadID * 100 + i;
printf("Store : %d\n", *ptr);
pthread_yield();
printf("Thread : %d Retrieve : %d\n", curr_threadID, *ptr);
}
printf("Done\n");
void *value_ptr = NULL;
pthread_exit(value_ptr);
return 0;
}