-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
156 lines (125 loc) · 3.05 KB
/
main.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <windows.h>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "Locker.h"
#include "nested_locker.h"
#include "win_semaphor_thread.h"
#include "dlist.h"
#include "log.h"
#include "darray.h"
#include "sort.h"
#include "BiTree.h"
/*
dlist list = NULL;
int eq(void* data1,void* data2)
{
int* dat1 = (int*)data1;
int* dat2 = (int*)data2;
if(*dat1>*dat2)
{
return *dat1-*dat2;
}
else
{
return *dat2-*dat1;
}
}
int print(void* data)
{
printf("%d,",*(int*)data);
}
void thread_proc1( void *pParam )
{
int sleeptime = 0;
printf( "%s created.\n", pParam );
while(1)
{
void* data1 = NULL;
sleeptime = 1+(int)(10.0*rand()/(RAND_MAX+1.0));
data1 = malloc(sizeof(int));
*(int*)data1 = (int)(10.0*rand()/(RAND_MAX+1.0));
add(list,data1);
printf("Thread1 Add %d to the list.\n",*(int*)data1);
printf("The all data of the list printed by thread1.\n");
foreach(list,print,NULL);
printf("Thread1 sleep for %d time.\n",sleeptime);
Sleep(1000*sleeptime);
}
}
void thread_proc2( void *pParam )
{
int sleeptime = 0;
printf( "%s created.\n", pParam );
while(1)
{
void* data1 = NULL;
sleeptime = 1+(int)(10.0*rand()/(RAND_MAX+1.0));
data1 = malloc(sizeof(int));
*(int*)data1 = (int)(10.0*rand()/(RAND_MAX+1.0));
delNode(list,data1,eq);
printf("Thread2 Delete data %d from the list.\n",*(int*)data1);
printf("The all data of the list printed by thread2.\n");
foreach(list,print,NULL);
printf("Thread2 sleep for %d time.\n",sleeptime);
Sleep(1000*sleeptime);
}
}
*/
void print(void* dat)
{
printf("%d ",*(int*)dat);
}
int main(int argc,char** argv)
{
//void* ctx = NULL;
//int sleeptime = 0;
//int i;
//void* data = NULL;
//DArray* darr = NULL;
Logger* log = NULL;
Locker* locker = locker_win_create();
//Locker* nest_locker = locker_nest_create(locker, (TaskSelfFunc)GetCurrentThreadId);
//init(&list,nest_locker);
//_beginthread( thread_proc1, 4096,"Thread 1");
//_beginthread( thread_proc2, 4096,"Thread 2");
log = create_log("D:\\log.log",locker,3);
log->all(log,
__FILE__,
__LINE__,
__FUNCTION__,
"this is my %dth test of print %s",
3,
"test zsl log");
log->warn(log,
__FILE__,
__LINE__,
__FUNCTION__,
"this is my %dth test of print %s",
4,
"test zsl log");
//log->debug(log,"Test the var list First: and second :\n");
//log->info(log,"this is my %dth test of print %s",4,"test zsl log");
//log->warn(log,"this is my %dth test of print %s",5,"test zsl log");
//log->error(log,"this is my %dth test of print %s",6,"test zsl log");
//log->fatal(log,"this is my %dth test of print %s",7,"test zsl log");
/*
darr = darray_create(free,ctx,NULL);
for(i = 0 ;i<100;i++)
{
data = malloc(sizeof(int));
sleeptime = 1+(int)(10.0*rand()/(RAND_MAX+1.0));
*(int*)data = sleeptime;
darray_append(darr,data);
}
printf("The all data in the array.");
darray_foreach(darr,print,NULL);
printf("\n");
bubble_sort(darr,0);
printf("The all data in the array.");
darray_foreach(darr,print,NULL);
printf("\n");
*/
getchar();
return 0;
}