-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·85 lines (59 loc) · 1.86 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
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "logger.h"
int main(void)
{
//log4c_init();
//log4c_category_t* mycat = log4c_category_get("mycat");
LOG_INIT("mycat");
LOG_INFO("enter main()");
int a[] = {13, 10, 8, 5, 23, 11, 4, 85, 100, 50, 43, 33, 19, 76, 7, 27};
myqsort(a, 0, sizeof(a)/sizeof(int) - 1);
int i = 0;
for(; i < sizeof(a)/sizeof(int); i++)
printf("%d ", a[i]);
printf("\n");
int b[] = {13, 10, 8, 5, 23, 11, 4, 85, 100, 50, 43, 33, 19, 76, 7, 27};
int last = sizeof(b)/sizeof(int);
int* p = (int*)malloc(sizeof(int)*last);
mergesort(b, 0, last-1, p);
free(p);
i = 0;
for(; i < sizeof(b)/sizeof(int); i++)
printf("%d ", b[i]);
printf("\n");
curl_global_init(CURL_GLOBAL_ALL);
pthread_cond_init(&g_Cond, NULL);
pthread_mutex_init(&g_Locker, NULL);
pthread_t pthreadid[2];
struct THREADINFO threadinfo1;
threadinfo1.uUserID = 111;
strncpy(threadinfo1.szURL, "http://www.baidu.com", 260);
strncpy(threadinfo1.szFile, "www.baidu.com.log", 260);
pthread_mutex_lock(&g_Locker);
int nRet = pthread_create(&pthreadid[0], NULL, threadFunc, &threadinfo1);
if(nRet == 0)
{
printf("create thread success, thread id = %lu\n", (unsigned long)pthreadid[0]);
pthread_cond_wait(&g_Cond, &g_Locker);
pthread_mutex_unlock(&g_Locker);
}
struct THREADINFO threadinfo2;
threadinfo2.uUserID = 222;
strncpy(threadinfo2.szURL, "http://www.google.com", 260);
strncpy(threadinfo2.szFile, "www.google.com.log", 260);
pthread_mutex_lock(&g_Locker);
nRet = pthread_create(&pthreadid[1], NULL, threadFunc, &threadinfo2);
if(nRet == 0)
{
printf("create thread success, thread id = %lu\n", (unsigned long)pthreadid[1]);
pthread_cond_wait(&g_Cond, &g_Locker);
pthread_mutex_unlock(&g_Locker);
}
pthread_join(pthreadid[0], NULL);
pthread_join(pthreadid[1], NULL);
curl_global_cleanup();
LOG_UNINIT();
return 0;
}